Work in progress
This commit is contained in:
@ -87,6 +87,7 @@
|
||||
</ResourceDictionary>
|
||||
</Grid.Resources>
|
||||
</Grid>
|
||||
<ListView x:Name="DataList" Grid.Row="1" BackgroundColor="#222222" />
|
||||
<ContentView
|
||||
x:Name="_noDataView"
|
||||
Grid.RowSpan="2"
|
||||
|
@ -2,6 +2,7 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Windows.Input;
|
||||
@ -13,16 +14,15 @@ namespace Aurora.Design.Components.DataGrid
|
||||
public partial class DataGrid : Grid
|
||||
{
|
||||
#region Private Fields
|
||||
private IList<object> _internalItems;
|
||||
private ObservableCollection<object> _internalItems;
|
||||
|
||||
private Dictionary<int, SortingOrder> _sortingOrders;
|
||||
private ListView _listView;
|
||||
|
||||
#endregion Fields
|
||||
|
||||
#region Constructor
|
||||
|
||||
public DataGrid() : this(ListViewCachingStrategy.RecycleElement)
|
||||
public DataGrid() : this(ListViewCachingStrategy.RetainElement)
|
||||
{
|
||||
}
|
||||
|
||||
@ -33,35 +33,28 @@ namespace Aurora.Design.Components.DataGrid
|
||||
|
||||
_sortingOrders = new Dictionary<int, SortingOrder>();
|
||||
|
||||
_listView = new ListView(cachingStrategy)
|
||||
{
|
||||
BackgroundColor = Color.FromHex("#222222"),
|
||||
ItemTemplate = new DataGridRowTemplateSelector(),
|
||||
SeparatorVisibility = SeparatorVisibility.Default,
|
||||
};
|
||||
DataList.ItemTemplate = new DataGridRowTemplateSelector();
|
||||
|
||||
_listView.ItemSelected += (s, e) =>
|
||||
DataList.ItemSelected += (s, e) =>
|
||||
{
|
||||
if (SelectionEnabled)
|
||||
{
|
||||
SelectedItem = _listView.SelectedItem;
|
||||
SelectedItem = DataList.SelectedItem;
|
||||
}
|
||||
else
|
||||
{
|
||||
_listView.SelectedItem = null;
|
||||
DataList.SelectedItem = null;
|
||||
}
|
||||
|
||||
ItemSelected?.Invoke(this, e);
|
||||
};
|
||||
|
||||
_listView.Refreshing += (s, e) =>
|
||||
DataList.Refreshing += (s, e) =>
|
||||
{
|
||||
Refreshing?.Invoke(this, e);
|
||||
};
|
||||
|
||||
_listView.SetBinding(ListView.RowHeightProperty, new Binding("RowHeight", source: this));
|
||||
Grid.SetRow(_listView, 1);
|
||||
Children.Add(_listView);
|
||||
DataList.SetBinding(ListView.RowHeightProperty, new Binding("RowHeight", source: this));
|
||||
}
|
||||
#endregion Constructor
|
||||
|
||||
@ -151,29 +144,29 @@ namespace Aurora.Design.Components.DataGrid
|
||||
defaultValueCreator: bindable => { return new ColumnCollection(); }
|
||||
);
|
||||
|
||||
public static readonly BindableProperty ItemsSourceProperty =
|
||||
public static BindableProperty ItemsSourceProperty =
|
||||
BindableProperty.Create(
|
||||
nameof(ItemsSource),
|
||||
typeof(IEnumerable),
|
||||
typeof(DataGrid),
|
||||
null,
|
||||
propertyName: nameof(ItemsSource),
|
||||
returnType: typeof(IEnumerable),
|
||||
declaringType: typeof(DataGrid),
|
||||
defaultBindingMode: BindingMode.TwoWay,
|
||||
propertyChanged: (bindable, oldValue, newValue) =>
|
||||
{
|
||||
DataGrid self = bindable as DataGrid;
|
||||
//ObservableCollection Tracking
|
||||
if (oldValue != null && oldValue is INotifyCollectionChanged)
|
||||
(oldValue as INotifyCollectionChanged).CollectionChanged -= self.HandleItemsSourceCollectionChanged;
|
||||
|
||||
if (newValue != null)
|
||||
{
|
||||
if (newValue is INotifyCollectionChanged)
|
||||
{
|
||||
(newValue as INotifyCollectionChanged).CollectionChanged += self.HandleItemsSourceCollectionChanged;
|
||||
}
|
||||
self.InternalItems = new List<object>(((IEnumerable)newValue).Cast<object>());
|
||||
(oldValue as INotifyCollectionChanged).CollectionChanged -= self.HandleItemsSourceCollectionChanged;
|
||||
}
|
||||
|
||||
if (newValue != null && newValue is INotifyCollectionChanged)
|
||||
{
|
||||
(newValue as INotifyCollectionChanged).CollectionChanged += self.HandleItemsSourceCollectionChanged;
|
||||
|
||||
self.InternalItems = new ObservableCollection<object>(((IEnumerable<object>)newValue));
|
||||
//Assign listview item source
|
||||
// self._listView.ItemsSource = self.InternalItems;
|
||||
self._listView.SetBinding(ListView.ItemsSourceProperty, new Binding("ItemsSource", source: self));
|
||||
self.DataList.ItemsSource = self.InternalItems;
|
||||
self.DataList.SetBinding(ListView.ItemsSourceProperty, new Binding("ItemsSource", source: self));
|
||||
}
|
||||
|
||||
if (self.SelectedItem != null && !self.InternalItems.Contains(self.SelectedItem))
|
||||
@ -181,7 +174,6 @@ namespace Aurora.Design.Components.DataGrid
|
||||
self.SelectedItem = null;
|
||||
}
|
||||
|
||||
|
||||
if (self.NoDataView != null)
|
||||
{
|
||||
if (self.ItemsSource == null || self.InternalItems.Count() == 0)
|
||||
@ -197,7 +189,7 @@ namespace Aurora.Design.Components.DataGrid
|
||||
});
|
||||
private void HandleItemsSourceCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
|
||||
{
|
||||
// InternalItems = new List<object>(((IEnumerable)sender).Cast<object>());
|
||||
|
||||
if (e.NewItems != null)
|
||||
{
|
||||
foreach (object item in e.NewItems)
|
||||
@ -224,7 +216,7 @@ namespace Aurora.Design.Components.DataGrid
|
||||
propertyChanged: (bindable, oldValue, newValue) =>
|
||||
{
|
||||
var self = bindable as DataGrid;
|
||||
self._listView.RowHeight = (int)newValue;
|
||||
self.DataList.RowHeight = (int)newValue;
|
||||
});
|
||||
|
||||
|
||||
@ -275,9 +267,9 @@ namespace Aurora.Design.Components.DataGrid
|
||||
propertyChanged: (bindable, oldValue, newValue) =>
|
||||
{
|
||||
var self = bindable as DataGrid;
|
||||
if (self._listView.SelectedItem != newValue)
|
||||
if (self.DataList.SelectedItem != newValue)
|
||||
{
|
||||
self._listView.SelectedItem = newValue;
|
||||
self.DataList.SelectedItem = newValue;
|
||||
}
|
||||
}
|
||||
);
|
||||
@ -300,13 +292,13 @@ namespace Aurora.Design.Components.DataGrid
|
||||
var self = bindable as DataGrid;
|
||||
if (newValue == null)
|
||||
{
|
||||
self._listView.IsPullToRefreshEnabled = false;
|
||||
self._listView.RefreshCommand = null;
|
||||
self.DataList.IsPullToRefreshEnabled = false;
|
||||
self.DataList.RefreshCommand = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
self._listView.IsPullToRefreshEnabled = true;
|
||||
self._listView.RefreshCommand = newValue as ICommand;
|
||||
self.DataList.IsPullToRefreshEnabled = true;
|
||||
self.DataList.RefreshCommand = newValue as ICommand;
|
||||
}
|
||||
});
|
||||
|
||||
@ -319,7 +311,7 @@ namespace Aurora.Design.Components.DataGrid
|
||||
BindingMode.TwoWay,
|
||||
propertyChanged: (bindable, oldValue, newValue) =>
|
||||
{
|
||||
(bindable as DataGrid)._listView.IsRefreshing = (bool)newValue;
|
||||
(bindable as DataGrid).DataList.IsRefreshing = (bool)newValue;
|
||||
});
|
||||
|
||||
public static readonly BindableProperty BorderThicknessProperty =
|
||||
@ -480,7 +472,7 @@ namespace Aurora.Design.Components.DataGrid
|
||||
set { SetValue(ItemsSourceProperty, value); }
|
||||
}
|
||||
|
||||
internal IList<object> InternalItems
|
||||
internal ObservableCollection<object> InternalItems
|
||||
{
|
||||
get { return _internalItems; }
|
||||
set
|
||||
@ -493,8 +485,7 @@ namespace Aurora.Design.Components.DataGrid
|
||||
SortItems(SortedColumnIndex);
|
||||
}
|
||||
}
|
||||
// _listView.ItemsSource = _internalItems;
|
||||
|
||||
DataList.ItemsSource = _internalItems;
|
||||
}
|
||||
}
|
||||
|
||||
@ -638,7 +629,7 @@ namespace Aurora.Design.Components.DataGrid
|
||||
|
||||
private void Reload()
|
||||
{
|
||||
InternalItems = new List<object>(_internalItems);
|
||||
InternalItems = new ObservableCollection<object>(_internalItems);
|
||||
}
|
||||
private void SortItems(SortData sData)
|
||||
{
|
||||
@ -655,10 +646,10 @@ namespace Aurora.Design.Components.DataGrid
|
||||
throw new InvalidOperationException("Please set the PropertyName property of Column");
|
||||
|
||||
//Sort
|
||||
if (order == SortingOrder.Descendant)
|
||||
items = items.OrderByDescending(x => ReflectionUtils.GetValueByPath(x, column.PropertyName)).ToList();
|
||||
else
|
||||
items = items.OrderBy(x => ReflectionUtils.GetValueByPath(x, column.PropertyName)).ToList();
|
||||
// if (order == SortingOrder.Descendant)
|
||||
// items = items.OrderByDescending(x => ReflectionUtils.GetValueByPath(x, column.PropertyName)).ToList();
|
||||
// else
|
||||
// items = items.OrderBy(x => ReflectionUtils.GetValueByPath(x, column.PropertyName)).ToList();
|
||||
|
||||
column.SortingIcon.Style = (order == SortingOrder.Descendant) ?
|
||||
AscendingIconStyle ?? (Style)_headerView.Resources["DescendingIconStyle"] :
|
||||
|
@ -12,15 +12,17 @@ namespace Aurora.Design.Components.DataGrid
|
||||
|
||||
protected override DataTemplate OnSelectTemplate(object item, BindableObject container)
|
||||
{
|
||||
var listView = container as ListView;
|
||||
var dataGrid = listView.Parent as DataGrid;
|
||||
ListView listView = container as ListView;
|
||||
DataGrid dataGrid = listView.Parent as DataGrid;
|
||||
var items = dataGrid.InternalItems;
|
||||
|
||||
_dataGridRowTemplate.SetValue(DataGridViewCell.DataGridProperty, dataGrid);
|
||||
_dataGridRowTemplate.SetValue(DataGridViewCell.RowContextProperty, item);
|
||||
|
||||
if (items != null)
|
||||
{
|
||||
_dataGridRowTemplate.SetValue(DataGridViewCell.IndexProperty, items.IndexOf(item));
|
||||
}
|
||||
|
||||
return _dataGridRowTemplate;
|
||||
}
|
||||
|
@ -32,15 +32,26 @@ namespace Aurora.Design.Components.DataGrid
|
||||
|
||||
#region Bindable Properties
|
||||
public static readonly BindableProperty DataGridProperty =
|
||||
BindableProperty.Create(nameof(DataGrid), typeof(DataGrid), typeof(DataGridViewCell), null,
|
||||
BindableProperty.Create(
|
||||
nameof(DataGrid),
|
||||
typeof(DataGrid),
|
||||
typeof(DataGridViewCell),
|
||||
null,
|
||||
propertyChanged: (b, o, n) => (b as DataGridViewCell).CreateView());
|
||||
|
||||
public static readonly BindableProperty IndexProperty =
|
||||
BindableProperty.Create(nameof(Index), typeof(int), typeof(DataGridViewCell), 0,
|
||||
BindableProperty.Create(
|
||||
nameof(Index),
|
||||
typeof(int),
|
||||
typeof(DataGridViewCell),
|
||||
0,
|
||||
propertyChanged: (b, o, n) => (b as DataGridViewCell).UpdateBackgroundColor());
|
||||
|
||||
public static readonly BindableProperty RowContextProperty =
|
||||
BindableProperty.Create(nameof(RowContext), typeof(object), typeof(DataGridViewCell),
|
||||
BindableProperty.Create(
|
||||
nameof(RowContext),
|
||||
typeof(object),
|
||||
typeof(DataGridViewCell),
|
||||
propertyChanged: (b, o, n) => (b as DataGridViewCell).UpdateBackgroundColor());
|
||||
#endregion
|
||||
|
||||
|
@ -2,8 +2,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xamarin.Forms;
|
||||
using System.ComponentModel;
|
||||
using System.Collections.Specialized;
|
||||
|
||||
namespace Aurora.Design.Components.Library
|
||||
{
|
||||
@ -33,51 +31,9 @@ namespace Aurora.Design.Components.Library
|
||||
propertyChanged: (BindableObject bindable, object oldValue, object newValue) =>
|
||||
{
|
||||
Library control = bindable as Library;
|
||||
|
||||
var libraryDataGrid = control.LibraryDataGrid;
|
||||
libraryDataGrid.ItemsSource = newValue as IEnumerable<object>;
|
||||
if (newValue is INotifyPropertyChanged)
|
||||
{
|
||||
var collection = newValue as INotifyCollectionChanged;
|
||||
collection.CollectionChanged += (object sender, NotifyCollectionChangedEventArgs eventArgs) =>
|
||||
OnItemSourceCollectionChanged(sender, eventArgs, bindable);
|
||||
}
|
||||
|
||||
if (oldValue is INotifyPropertyChanged)
|
||||
{
|
||||
var collection = newValue as INotifyCollectionChanged;
|
||||
collection.CollectionChanged -= (object sender, NotifyCollectionChangedEventArgs eventArgs) =>
|
||||
OnItemSourceCollectionChanged(sender, eventArgs, bindable);
|
||||
}
|
||||
control.LibraryDataGrid.ItemsSource = (IEnumerable<object>)newValue;
|
||||
});
|
||||
|
||||
private static void OnItemSourceCollectionChanged(object sender, NotifyCollectionChangedEventArgs e, BindableObject bindable)
|
||||
{
|
||||
if (sender is IEnumerable<object>)
|
||||
{
|
||||
Library control = bindable as Library;
|
||||
var libraryDataGrid = control.LibraryDataGrid;
|
||||
var collection = libraryDataGrid.ItemsSource as IEnumerable<object>;
|
||||
if (e.NewItems != null)
|
||||
{
|
||||
foreach (object obj in e.NewItems)
|
||||
{
|
||||
collection.Concat(new[] { obj });
|
||||
}
|
||||
}
|
||||
|
||||
if (e.OldItems != null)
|
||||
{
|
||||
foreach (object obj in e.OldItems)
|
||||
{
|
||||
var list = collection.ToList();
|
||||
list.Remove(obj);
|
||||
collection = list;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Backing property for the ItemsSource property.
|
||||
@ -164,10 +120,10 @@ namespace Aurora.Design.Components.Library
|
||||
private static void OnDoubleClickPropertyChanged(BindableObject bindable, object newValue, object oldValue)
|
||||
{
|
||||
Library control = bindable as Library;
|
||||
var queueDataGrid = control.LibraryDataGrid;
|
||||
if (queueDataGrid.GestureRecognizers.Count > 0)
|
||||
var dataGrid = control.LibraryDataGrid;
|
||||
if (dataGrid.GestureRecognizers.Count > 0)
|
||||
{
|
||||
var gestureRecognizer = queueDataGrid.GestureRecognizers.First();
|
||||
var gestureRecognizer = dataGrid.GestureRecognizers.First();
|
||||
|
||||
if (gestureRecognizer is TapGestureRecognizer)
|
||||
{
|
||||
|
Reference in New Issue
Block a user