2019-05-31 14:12:03 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using Xamarin.Forms;
|
|
|
|
|
|
2019-12-01 11:53:30 +00:00
|
|
|
|
namespace Aurora.Design.Components.Library
|
2019-05-31 14:12:03 +00:00
|
|
|
|
{
|
2019-12-01 11:53:30 +00:00
|
|
|
|
public partial class Library : ContentView
|
2019-05-31 14:12:03 +00:00
|
|
|
|
{
|
2019-12-01 11:53:30 +00:00
|
|
|
|
public Library()
|
2019-05-31 14:12:03 +00:00
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2019-12-01 11:53:30 +00:00
|
|
|
|
this.LibraryDataGrid.ItemSelected += (sender, e) =>
|
2019-11-04 04:17:34 +00:00
|
|
|
|
{
|
|
|
|
|
this.SelectedItem = e.SelectedItem;
|
|
|
|
|
};
|
2019-05-31 14:12:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#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>),
|
2019-12-01 11:53:30 +00:00
|
|
|
|
declaringType: typeof(Library),
|
2019-05-31 14:12:03 +00:00
|
|
|
|
defaultBindingMode: BindingMode.Default,
|
2019-12-10 20:10:27 +00:00
|
|
|
|
propertyChanged: (BindableObject bindable, object oldValue, object newValue) =>
|
|
|
|
|
{
|
|
|
|
|
Library control = bindable as Library;
|
2019-12-19 01:23:59 +00:00
|
|
|
|
control.LibraryDataGrid.ItemsSource = (IEnumerable<object>)newValue;
|
2019-12-10 20:10:27 +00:00
|
|
|
|
});
|
|
|
|
|
|
2019-05-31 14:12:03 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Backing property for the ItemsSource property.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value></value>
|
|
|
|
|
public IEnumerable<object> ItemsSource
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return (IEnumerable<object>)GetValue(ItemsSourceProperty);
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
SetValue(ItemsSourceProperty, value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#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),
|
2019-12-01 11:53:30 +00:00
|
|
|
|
declaringType: typeof(Library),
|
2019-11-04 04:17:34 +00:00
|
|
|
|
defaultBindingMode: BindingMode.TwoWay);
|
2019-05-31 14:12:03 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Backing property for the SelectedItem property.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value></value>
|
|
|
|
|
public object SelectedItem
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return ((object)GetValue(SelectedItemProperty));
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
SetValue(SelectedItemProperty, value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-04 04:17:34 +00:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Bindable property for the item double clicked command
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name=""SelectedItem""></param>
|
|
|
|
|
/// <param name="typeof(BaseMetadata"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static readonly BindableProperty ItemDoubleClickedProperty =
|
|
|
|
|
BindableProperty.Create(propertyName: "ItemDoubleClicked",
|
|
|
|
|
returnType: typeof(Command),
|
2019-12-01 11:53:30 +00:00
|
|
|
|
declaringType: typeof(Library),
|
2019-11-04 04:17:34 +00:00
|
|
|
|
propertyChanged: OnDoubleClickPropertyChanged);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Public backing property
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <value></value>
|
|
|
|
|
public Command ItemDoubleClicked
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return (Command)GetValue(ItemDoubleClickedProperty);
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
SetValue(ItemDoubleClickedProperty, value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-31 14:12:03 +00:00
|
|
|
|
/// <summary>
|
2019-11-04 04:17:34 +00:00
|
|
|
|
/// Event handler for double click property. Adds command execute handler.
|
2019-05-31 14:12:03 +00:00
|
|
|
|
/// </summary>
|
2019-11-04 04:17:34 +00:00
|
|
|
|
/// <param name="bindable"></param>
|
2019-05-31 14:12:03 +00:00
|
|
|
|
/// <param name="newValue"></param>
|
|
|
|
|
/// <param name="oldValue"></param>
|
2019-11-04 04:17:34 +00:00
|
|
|
|
private static void OnDoubleClickPropertyChanged(BindableObject bindable, object newValue, object oldValue)
|
2019-05-31 14:12:03 +00:00
|
|
|
|
{
|
2019-12-01 11:53:30 +00:00
|
|
|
|
Library control = bindable as Library;
|
2019-12-19 01:23:59 +00:00
|
|
|
|
var dataGrid = control.LibraryDataGrid;
|
|
|
|
|
if (dataGrid.GestureRecognizers.Count > 0)
|
2019-05-31 14:12:03 +00:00
|
|
|
|
{
|
2019-12-19 01:23:59 +00:00
|
|
|
|
var gestureRecognizer = dataGrid.GestureRecognizers.First();
|
2019-05-31 14:12:03 +00:00
|
|
|
|
|
2019-11-04 04:17:34 +00:00
|
|
|
|
if (gestureRecognizer is TapGestureRecognizer)
|
|
|
|
|
{
|
|
|
|
|
TapGestureRecognizer tap = gestureRecognizer as TapGestureRecognizer;
|
|
|
|
|
tap.Tapped += (sender, e) =>
|
|
|
|
|
{
|
|
|
|
|
control.ItemDoubleClicked.Execute(null);
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-05-31 14:12:03 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|