This repository has been archived on 2020-12-20. You can view files and clone it, but cannot push or open issues or pull requests.
aurora-sharp-desktop/Aurora/Frontend/Components/Queue/Queue.xaml.cs

110 lines
3.6 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.Linq;
using Xamarin.Forms;
using Xamarin.Forms.DataGrid;
using Aurora.Backend.Models.Media;
namespace Aurora.Frontend.Components.Queue
{
public partial class Queue : ContentView
{
public Queue()
{
InitializeComponent();
}
#region ItemsSource Property
/// <summary>
/// Bindable Property for the ItemsSource of the datagrid.
/// </summary>
/// <param name=""ItemsSource""></param>
/// <param name="typeof(IEnumerable<object>"></param>
/// <returns></returns>
public static readonly BindableProperty ItemsSourceProperty =
BindableProperty.Create(propertyName: "ItemsSource",
returnType: typeof(IEnumerable<object>),
declaringType: typeof(Queue),
defaultBindingMode: BindingMode.Default,
propertyChanged: OnItemsSourceChanged);
/// <summary>
/// Backing property for the ItemsSource property.
/// </summary>
/// <value></value>
public IEnumerable<object> ItemsSource
{
get
{
return (IEnumerable<object>)GetValue(ItemsSourceProperty);
}
set
{
SetValue(ItemsSourceProperty, value);
}
}
/// <summary>
/// ItemsSource Changed event handler
/// </summary>
/// <param name="bindable"></param>
/// <param name="oldValue"></param>
/// <param name="newValue"></param>
private static void OnItemsSourceChanged(BindableObject bindable, object oldValue, object newValue)
{
Queue control = bindable as Queue;
var queueDataGrid = control.FindByName("QueueDataGrid") as DataGrid;
queueDataGrid.ItemsSource = newValue as IEnumerable<object>;
}
#endregion ItemsSource Property
/// <summary>
/// Bindable property for the selected item field on the datagrid.
/// </summary>
/// <param name=""SelectedItem""></param>
/// <param name="typeof(BaseMetadata"></param>
/// <returns></returns>
public static readonly BindableProperty SelectedItemProperty =
BindableProperty.Create(propertyName: "SelectedItem",
returnType: typeof(object),
declaringType: typeof(Queue),
defaultBindingMode: BindingMode.TwoWay,
propertyChanged: OnSelectedItemChanged);
/// <summary>
/// Backing property for the SelectedItem property.
/// </summary>
/// <value></value>
public object SelectedItem
{
get
{
return ((object)GetValue(SelectedItemProperty));
}
set
{
SetValue(SelectedItemProperty, value);
}
}
/// <summary>
/// Handles selection change events.
/// </summary>
/// <param name="bindable">The bindable object.</param>
/// <param name="newValue"></param>
/// <param name="oldValue"></param>
private static void OnSelectedItemChanged(BindableObject bindable, object newValue, object oldValue)
{
Queue control = bindable as Queue;
var queueDataGrid = control.FindByName("QueueDataGrid") as DataGrid;
IEnumerable<object> source = (IEnumerable<object>)queueDataGrid.ItemsSource;
if (source.Contains(newValue))
{
queueDataGrid.SelectedItem = newValue;
}
}
}
}