Work in progress
This commit is contained in:
parent
555eb07ec1
commit
93dc9ae8c9
@ -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)
|
||||
{
|
||||
|
@ -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">
|
||||
<ContentPage.Content></ContentPage.Content>
|
||||
<ContentView.Content>
|
||||
|
||||
</ContentView.Content>
|
||||
</ContentView>
|
@ -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()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -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">
|
||||
<ContentView.Content>
|
||||
@ -20,17 +21,97 @@
|
||||
Members="{Binding Members}"/>
|
||||
<Label
|
||||
Text="Queue"/>
|
||||
<library:Library
|
||||
<dg:DataGrid
|
||||
x:Name="LibraryDataGrid"
|
||||
SelectionEnabled="True"
|
||||
RowHeight="30"
|
||||
BorderColor="#3a3a3a"
|
||||
BorderThickness="0"
|
||||
HeaderHeight="40"
|
||||
HeaderBackground="#222222"
|
||||
ItemsSource="{Binding Queue}">
|
||||
<dg:DataGrid.HeaderLabelStyle>
|
||||
<Style
|
||||
TargetType="Label">
|
||||
<Setter
|
||||
Property="HorizontalOptions"
|
||||
Value="Start"/>
|
||||
<Setter
|
||||
Property="FontSize"
|
||||
Value="14"/>
|
||||
<Setter
|
||||
Property="TextColor"
|
||||
Value="White"/>
|
||||
</Style>
|
||||
</dg:DataGrid.HeaderLabelStyle>
|
||||
<dg:DataGrid.GestureRecognizers>
|
||||
<TapGestureRecognizer
|
||||
NumberOfTapsRequired="2"/>
|
||||
</dg:DataGrid.GestureRecognizers>
|
||||
<dg:DataGrid.Columns>
|
||||
<dg:DataGridColumn
|
||||
Title=""
|
||||
PropertyName="Icon"
|
||||
Width="15">
|
||||
<dg:DataGridColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<Image
|
||||
Source="../../Resources/unselected.png"/>
|
||||
</DataTemplate>
|
||||
</dg:DataGridColumn.CellTemplate>
|
||||
</dg:DataGridColumn>
|
||||
<dg:DataGridColumn
|
||||
Title="Title"
|
||||
PropertyName="Metadata.Title"
|
||||
Width="2*">
|
||||
<dg:DataGridColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<Label
|
||||
LineBreakMode="TailTruncation"
|
||||
Text="{Binding .}"/>
|
||||
</DataTemplate>
|
||||
</dg:DataGridColumn.CellTemplate>
|
||||
</dg:DataGridColumn>
|
||||
<dg:DataGridColumn
|
||||
Title="Album"
|
||||
PropertyName="Metadata.Album"
|
||||
Width="0.95*">
|
||||
<dg:DataGridColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<Label
|
||||
LineBreakMode="TailTruncation"
|
||||
Text="{Binding .}"/>
|
||||
</DataTemplate>
|
||||
</dg:DataGridColumn.CellTemplate>
|
||||
</dg:DataGridColumn>
|
||||
<dg:DataGridColumn
|
||||
Title="Artist"
|
||||
PropertyName="Metadata.Artist"
|
||||
Width="1*">
|
||||
<dg:DataGridColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<Label
|
||||
LineBreakMode="TailTruncation"
|
||||
Text="{Binding .}"/>
|
||||
</DataTemplate>
|
||||
</dg:DataGridColumn.CellTemplate>
|
||||
</dg:DataGridColumn>
|
||||
</dg:DataGrid.Columns>
|
||||
<dg:DataGrid.RowsTextColorPalette>
|
||||
<dg:PaletteCollection>
|
||||
<Color>White</Color>
|
||||
</dg:PaletteCollection>
|
||||
</dg:DataGrid.RowsTextColorPalette>
|
||||
<dg:DataGrid.RowsBackgroundColorPalette>
|
||||
<dg:PaletteCollection>
|
||||
<Color>Transparent</Color>
|
||||
</dg:PaletteCollection>
|
||||
</dg:DataGrid.RowsBackgroundColorPalette>
|
||||
</dg:DataGrid><!-- <library:Library
|
||||
ItemsSource="{Binding Queue}"
|
||||
SelectedItem="{Binding SelectedSong}"
|
||||
ItemDoubleClicked="{Binding PlayCommand}"/>
|
||||
</StackLayout><!--<hs:HostSelector
|
||||
Grid.Row="0"
|
||||
x:Name="HostSelectionDialog"
|
||||
Hostname="{Binding Hostname}"
|
||||
HostCommand="{Binding HostCommand}"
|
||||
JoinCommand="{Binding JoinCommand}"
|
||||
IsVisible="{Binding IsSelectingHost}"/>-->
|
||||
ItemDoubleClicked="{Binding PlayCommand}"/> -->
|
||||
</StackLayout>
|
||||
</Grid>
|
||||
</ContentView.Content>
|
||||
</ContentView>
|
@ -390,6 +390,7 @@ namespace Aurora.Design.Views.Party
|
||||
_client.RemoteSyncClient);
|
||||
|
||||
Queue.Add(remote);
|
||||
OnPropertyChanged("Queue");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
Loading…
Reference in New Issue
Block a user