From 93dc9ae8c96354d0eae2354a5b59b963faa76d8b Mon Sep 17 00:00:00 2001 From: watsonb8 Date: Wed, 18 Dec 2019 20:23:59 -0500 Subject: [PATCH] Work in progress --- .../Design/Components/DataGrid/DataGrid.xaml | 1 + .../Components/DataGrid/DataGrid.xaml.cs | 89 ++++++++--------- .../DataGrid/DataGridRowTemplateSelector.cs | 6 +- .../Components/DataGrid/DataGridViewCell.cs | 17 +++- .../Design/Components/Library/Library.xaml.cs | 52 +--------- Aurora/Design/Views/Artists/ArtistsView.xaml | 4 +- .../Design/Views/Artists/ArtistsViewModel.cs | 9 ++ Aurora/Design/Views/Party/PartyView.xaml | 99 +++++++++++++++++-- Aurora/Design/Views/Party/PartyViewModel.cs | 1 + 9 files changed, 166 insertions(+), 112 deletions(-) diff --git a/Aurora/Design/Components/DataGrid/DataGrid.xaml b/Aurora/Design/Components/DataGrid/DataGrid.xaml index e93ba85..d6ae78c 100644 --- a/Aurora/Design/Components/DataGrid/DataGrid.xaml +++ b/Aurora/Design/Components/DataGrid/DataGrid.xaml @@ -87,6 +87,7 @@ + _internalItems; + private ObservableCollection _internalItems; private Dictionary _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(); - _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(((IEnumerable)newValue).Cast()); + (oldValue as INotifyCollectionChanged).CollectionChanged -= self.HandleItemsSourceCollectionChanged; + } + + if (newValue != null && newValue is INotifyCollectionChanged) + { + (newValue as INotifyCollectionChanged).CollectionChanged += self.HandleItemsSourceCollectionChanged; + + self.InternalItems = new ObservableCollection(((IEnumerable)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(((IEnumerable)sender).Cast()); + 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 InternalItems + internal ObservableCollection 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(_internalItems); + InternalItems = new ObservableCollection(_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"] : diff --git a/Aurora/Design/Components/DataGrid/DataGridRowTemplateSelector.cs b/Aurora/Design/Components/DataGrid/DataGridRowTemplateSelector.cs index f83e06c..b27648b 100644 --- a/Aurora/Design/Components/DataGrid/DataGridRowTemplateSelector.cs +++ b/Aurora/Design/Components/DataGrid/DataGridRowTemplateSelector.cs @@ -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; } diff --git a/Aurora/Design/Components/DataGrid/DataGridViewCell.cs b/Aurora/Design/Components/DataGrid/DataGridViewCell.cs index f8208f5..7ba1c1f 100644 --- a/Aurora/Design/Components/DataGrid/DataGridViewCell.cs +++ b/Aurora/Design/Components/DataGrid/DataGridViewCell.cs @@ -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 diff --git a/Aurora/Design/Components/Library/Library.xaml.cs b/Aurora/Design/Components/Library/Library.xaml.cs index f8d80e6..698dd90 100644 --- a/Aurora/Design/Components/Library/Library.xaml.cs +++ b/Aurora/Design/Components/Library/Library.xaml.cs @@ -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; - 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)newValue; }); - private static void OnItemSourceCollectionChanged(object sender, NotifyCollectionChangedEventArgs e, BindableObject bindable) - { - if (sender is IEnumerable) - { - Library control = bindable as Library; - var libraryDataGrid = control.LibraryDataGrid; - var collection = libraryDataGrid.ItemsSource as IEnumerable; - 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; - } - } - } - } - /// /// 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) { diff --git a/Aurora/Design/Views/Artists/ArtistsView.xaml b/Aurora/Design/Views/Artists/ArtistsView.xaml index 4ab6661..b56d9a0 100644 --- a/Aurora/Design/Views/Artists/ArtistsView.xaml +++ b/Aurora/Design/Views/Artists/ArtistsView.xaml @@ -3,5 +3,7 @@ xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="Aurora.Design.Views.Artists.ArtistsView"> - + + + \ No newline at end of file diff --git a/Aurora/Design/Views/Artists/ArtistsViewModel.cs b/Aurora/Design/Views/Artists/ArtistsViewModel.cs index 5ffd44a..aa9cb03 100644 --- a/Aurora/Design/Views/Artists/ArtistsViewModel.cs +++ b/Aurora/Design/Views/Artists/ArtistsViewModel.cs @@ -1,10 +1,19 @@ using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Threading.Tasks; namespace Aurora.Design.Views.Artists { + public class TestObj + { + public string Test1 { get; set; } + public string Test2 { get; set; } + } public class ArtistsViewModel : BaseViewModel { public ArtistsViewModel() { } + } } diff --git a/Aurora/Design/Views/Party/PartyView.xaml b/Aurora/Design/Views/Party/PartyView.xaml index db599dd..8992fe9 100644 --- a/Aurora/Design/Views/Party/PartyView.xaml +++ b/Aurora/Design/Views/Party/PartyView.xaml @@ -3,6 +3,7 @@ xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:ml="clr-namespace:Aurora.Design.Components.MemberList" + xmlns:dg="clr-namespace:Aurora.Design.Components.DataGrid" xmlns:library="clr-namespace:Aurora.Design.Components.Library" x:Class="Aurora.Design.Views.Party.PartyView"> @@ -20,17 +21,97 @@ Members="{Binding Members}"/> \ No newline at end of file diff --git a/Aurora/Design/Views/Party/PartyViewModel.cs b/Aurora/Design/Views/Party/PartyViewModel.cs index ac7d792..71155f1 100644 --- a/Aurora/Design/Views/Party/PartyViewModel.cs +++ b/Aurora/Design/Views/Party/PartyViewModel.cs @@ -390,6 +390,7 @@ namespace Aurora.Design.Views.Party _client.RemoteSyncClient); Queue.Add(remote); + OnPropertyChanged("Queue"); } } catch (Exception ex)