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