diff --git a/aurora-sharp-desktop/Aurora.gtk/Aurora.gtk.csproj b/aurora-sharp-desktop/Aurora.gtk/Aurora.gtk.csproj index d80583a..a25420a 100644 --- a/aurora-sharp-desktop/Aurora.gtk/Aurora.gtk.csproj +++ b/aurora-sharp-desktop/Aurora.gtk/Aurora.gtk.csproj @@ -1,6 +1,6 @@ - + Debug @@ -28,42 +28,24 @@ - - False - - - False - - - False - - - False - - - False - - - False - - ..\packages\Xamarin.Forms.4.3.0.991211\lib\netstandard2.0\Xamarin.Forms.Core.dll + ..\packages\Xamarin.Forms.5.0.0.2012\lib\netstandard2.0\Xamarin.Forms.Core.dll - ..\packages\Xamarin.Forms.4.3.0.991211\lib\netstandard2.0\Xamarin.Forms.Platform.dll + ..\packages\Xamarin.Forms.5.0.0.2012\lib\netstandard2.0\Xamarin.Forms.Platform.dll - ..\packages\Xamarin.Forms.4.3.0.991211\lib\netstandard2.0\Xamarin.Forms.Xaml.dll + ..\packages\Xamarin.Forms.5.0.0.2012\lib\netstandard2.0\Xamarin.Forms.Xaml.dll ..\packages\OpenTK.3.1.0\lib\net20\OpenTK.dll - ..\packages\Xamarin.Forms.Platform.GTK.4.3.0.991211\lib\net45\webkit-sharp.dll + ..\packages\Xamarin.Forms.Platform.GTK.5.0.0.2012\lib\net45\webkit-sharp.dll - ..\packages\Xamarin.Forms.Platform.GTK.4.3.0.991211\lib\net45\Xamarin.Forms.Platform.GTK.dll + ..\packages\Xamarin.Forms.Platform.GTK.5.0.0.2012\lib\net45\Xamarin.Forms.Platform.GTK.dll ..\packages\System.Reflection.4.3.0\lib\net462\System.Reflection.dll @@ -168,6 +150,15 @@ ..\packages\Autofac.5.0.0\lib\net461\Autofac.dll + + + + + + + + ..\packages\Xamarin.Forms.DataGrid.4.8.0\lib\netstandard2.0\Xamarin.Forms.DataGrid.dll + @@ -545,5 +536,5 @@ - + \ No newline at end of file diff --git a/aurora-sharp-desktop/Aurora.gtk/gtk-gui/gui.stetic b/aurora-sharp-desktop/Aurora.gtk/gtk-gui/gui.stetic index 0d4f676..6b77eb7 100644 --- a/aurora-sharp-desktop/Aurora.gtk/gtk-gui/gui.stetic +++ b/aurora-sharp-desktop/Aurora.gtk/gtk-gui/gui.stetic @@ -2,6 +2,7 @@ .. + 2.12 diff --git a/aurora-sharp-desktop/Aurora.gtk/packages.config b/aurora-sharp-desktop/Aurora.gtk/packages.config index 45a8c07..1bce156 100644 --- a/aurora-sharp-desktop/Aurora.gtk/packages.config +++ b/aurora-sharp-desktop/Aurora.gtk/packages.config @@ -8,7 +8,7 @@ - + @@ -25,7 +25,7 @@ - + @@ -34,6 +34,7 @@ - - + + + \ No newline at end of file diff --git a/aurora-sharp-desktop/Aurora.test/Aurora.test.csproj b/aurora-sharp-desktop/Aurora.test/Aurora.test.csproj index 124b6ea..7d9a160 100644 --- a/aurora-sharp-desktop/Aurora.test/Aurora.test.csproj +++ b/aurora-sharp-desktop/Aurora.test/Aurora.test.csproj @@ -23,9 +23,6 @@ - - PreserveNewest - PreserveNewest @@ -56,62 +53,11 @@ PreserveNewest - - PreserveNewest - PreserveNewest PreserveNewest - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - - - PreserveNewest - \ No newline at end of file diff --git a/aurora-sharp-desktop/Aurora/Aurora.csproj b/aurora-sharp-desktop/Aurora/Aurora.csproj index 27f0f48..84def05 100644 --- a/aurora-sharp-desktop/Aurora/Aurora.csproj +++ b/aurora-sharp-desktop/Aurora/Aurora.csproj @@ -5,11 +5,12 @@ pdbonly + true - - + + @@ -24,6 +25,7 @@ + @@ -43,7 +45,6 @@ - diff --git a/aurora-sharp-desktop/Aurora/Design/Components/DataGrid/ColumnCollection.cs b/aurora-sharp-desktop/Aurora/Design/Components/DataGrid/ColumnCollection.cs deleted file mode 100644 index 1906bcb..0000000 --- a/aurora-sharp-desktop/Aurora/Design/Components/DataGrid/ColumnCollection.cs +++ /dev/null @@ -1,8 +0,0 @@ -using System.Collections.Generic; - -namespace Aurora.Design.Components.DataGrid -{ - public sealed class ColumnCollection : List - { - } -} diff --git a/aurora-sharp-desktop/Aurora/Design/Components/DataGrid/DataGrid.xaml b/aurora-sharp-desktop/Aurora/Design/Components/DataGrid/DataGrid.xaml deleted file mode 100644 index d6ae78c..0000000 --- a/aurora-sharp-desktop/Aurora/Design/Components/DataGrid/DataGrid.xaml +++ /dev/null @@ -1,95 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/aurora-sharp-desktop/Aurora/Design/Components/DataGrid/DataGrid.xaml.cs b/aurora-sharp-desktop/Aurora/Design/Components/DataGrid/DataGrid.xaml.cs deleted file mode 100644 index fe7e878..0000000 --- a/aurora-sharp-desktop/Aurora/Design/Components/DataGrid/DataGrid.xaml.cs +++ /dev/null @@ -1,756 +0,0 @@ -using System; -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; -using Xamarin.Forms; -using Aurora.Utils; - -namespace Aurora.Design.Components.DataGrid -{ - public partial class DataGrid : Grid - { - #region Private Fields - private ObservableCollection _internalItems; - - private Dictionary _sortingOrders; - - #endregion Fields - - #region Constructor - - public DataGrid() : this(ListViewCachingStrategy.RetainElement) - { - } - - public DataGrid(ListViewCachingStrategy cachingStrategy) - { - InitializeComponent(); - BackgroundColor = Color.Transparent; - - _sortingOrders = new Dictionary(); - - DataList.ItemTemplate = new DataGridRowTemplateSelector(); - - DataList.ItemSelected += (s, e) => - { - if (SelectionEnabled) - { - SelectedItem = DataList.SelectedItem; - } - else - { - DataList.SelectedItem = null; - } - - ItemSelected?.Invoke(this, e); - }; - - DataList.Refreshing += (s, e) => - { - Refreshing?.Invoke(this, e); - }; - - DataList.SetBinding(ListView.RowHeightProperty, new Binding("RowHeight", source: this)); - } - #endregion Constructor - - #region Public Fields - public event EventHandler Refreshing; - public event EventHandler ItemSelected; - - #endregion Public Fields - - #region Bindable properties - public static readonly BindableProperty ActiveRowColorProperty = - BindableProperty.Create( - nameof(ActiveRowColor), - typeof(Color), - typeof(DataGrid), - Color.FromRgb(128, 144, 160), - coerceValue: (bindable, value) => - { - if (!(bindable as DataGrid).SelectionEnabled) - throw new InvalidOperationException("Datagrid must be SelectionEnabled=true to set ActiveRowColor"); - return value; - }); - - public static readonly BindableProperty HeaderBackgroundProperty = - BindableProperty.Create( - nameof(HeaderBackground), - typeof(Color), - typeof(DataGrid), - Color.White, - propertyChanged: (bindable, oldValue, newValue) => - { - var self = bindable as DataGrid; - if (self._headerView != null && !self.HeaderBordersVisible) - self._headerView.BackgroundColor = (Color)newValue; - }); - - public static readonly BindableProperty BorderColorProperty = - BindableProperty.Create( - nameof(BorderColor), - typeof(Color), - typeof(DataGrid), - Color.Black, - propertyChanged: (bindable, oldValue, newValue) => - { - var self = bindable as DataGrid; - if (self.HeaderBordersVisible) - self._headerView.BackgroundColor = (Color)newValue; - - if (self.Columns != null && self.ItemsSource != null) - self.Reload(); - }); - - public static readonly BindableProperty RowsBackgroundColorPaletteProperty = - BindableProperty.Create(nameof(RowsBackgroundColorPalette), - typeof(IColorProvider), - typeof(DataGrid), - new PaletteCollection { default(Color) }, - propertyChanged: (bindable, oldValue, newValue) => - { - var self = bindable as DataGrid; - if (self.Columns != null && self.ItemsSource != null) - self.Reload(); - }); - - public static readonly BindableProperty RowsTextColorPaletteProperty = - BindableProperty.Create( - nameof(RowsTextColorPalette), - typeof(IColorProvider), - typeof(DataGrid), - new PaletteCollection { Color.Black }, - propertyChanged: (bindable, oldValue, newValue) => - { - var self = bindable as DataGrid; - if (self.Columns != null && self.ItemsSource != null) - self.Reload(); - }); - - public static readonly BindableProperty ColumnsProperty = - BindableProperty.Create( - nameof(Columns), - typeof(ColumnCollection), - typeof(DataGrid), - propertyChanged: (bindable, oldValue, newValue) => - { - (bindable as DataGrid).InitHeaderView(); - }, - defaultValueCreator: bindable => { return new ColumnCollection(); } - ); - - public static BindableProperty ItemsSourceProperty = - BindableProperty.Create( - 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 && newValue is INotifyCollectionChanged) - { - (newValue as INotifyCollectionChanged).CollectionChanged += self.HandleItemsSourceCollectionChanged; - - self.InternalItems = new ObservableCollection(((IEnumerable)newValue)); - //Assign listview item source - self.DataList.ItemsSource = self.InternalItems; - self.DataList.SetBinding(ListView.ItemsSourceProperty, new Binding("ItemsSource", source: self)); - } - - if (self.SelectedItem != null && !self.InternalItems.Contains(self.SelectedItem)) - { - self.SelectedItem = null; - } - - if (self.NoDataView != null) - { - if (self.ItemsSource == null || self.InternalItems.Count() == 0) - { - self._noDataView.IsVisible = true; - } - - else if (self._noDataView.IsVisible) - { - self._noDataView.IsVisible = false; - } - } - }); - private void HandleItemsSourceCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) - { - - if (e.NewItems != null) - { - foreach (object item in e.NewItems) - { - InternalItems.Add(item); - } - } - - if (e.OldItems != null) - { - foreach (object item in e.OldItems) - { - InternalItems.Remove(item); - } - } - if (SelectedItem != null && !InternalItems.Contains(SelectedItem)) - { - SelectedItem = null; - } - } - - public static readonly BindableProperty RowHeightProperty = - BindableProperty.Create(nameof(RowHeight), typeof(int), typeof(DataGrid), 40, - propertyChanged: (bindable, oldValue, newValue) => - { - var self = bindable as DataGrid; - self.DataList.RowHeight = (int)newValue; - }); - - - public static readonly BindableProperty HeaderHeightProperty = - BindableProperty.Create(nameof(HeaderHeight), typeof(int), typeof(DataGrid), 40, - propertyChanged: (bindable, oldValue, newValue) => - { - var self = bindable as DataGrid; - self._headerView.HeightRequest = (int)newValue; - }); - - public static readonly BindableProperty IsSortableProperty = - BindableProperty.Create(nameof(IsSortable), typeof(bool), typeof(DataGrid), true); - - public static readonly BindableProperty FontSizeProperty = - BindableProperty.Create(nameof(FontSize), typeof(double), typeof(DataGrid), 13.0); - - public static readonly BindableProperty FontFamilyProperty = - BindableProperty.Create( - nameof(FontFamily), - typeof(string), - typeof(DataGrid), - Font.Default.FontFamily); - - public static readonly BindableProperty SelectedItemProperty = - BindableProperty.Create( - nameof(SelectedItem), - typeof(object), - typeof(DataGrid), - null, - BindingMode.TwoWay, - coerceValue: (bindable, value) => - { - var self = bindable as DataGrid; - if (!self.SelectionEnabled && value != null) - { - throw new InvalidOperationException("Datagrid must be SelectionEnabled=true to set SelectedItem"); - } - if (self.InternalItems != null && self.InternalItems.Contains(value)) - { - return value; - } - else - { - return null; - } - }, - propertyChanged: (bindable, oldValue, newValue) => - { - var self = bindable as DataGrid; - if (self.DataList.SelectedItem != newValue) - { - self.DataList.SelectedItem = newValue; - } - } - ); - - public static readonly BindableProperty SelectionEnabledProperty = - BindableProperty.Create(nameof(SelectionEnabled), typeof(bool), typeof(DataGrid), true, - propertyChanged: (bindable, oldValue, newValue) => - { - var self = bindable as DataGrid; - if (!self.SelectionEnabled && self.SelectedItem != null) - { - self.SelectedItem = null; - } - }); - - public static readonly BindableProperty PullToRefreshCommandProperty = - BindableProperty.Create(nameof(PullToRefreshCommand), typeof(ICommand), typeof(DataGrid), null, - propertyChanged: (bindable, oldValue, newValue) => - { - var self = bindable as DataGrid; - if (newValue == null) - { - self.DataList.IsPullToRefreshEnabled = false; - self.DataList.RefreshCommand = null; - } - else - { - self.DataList.IsPullToRefreshEnabled = true; - self.DataList.RefreshCommand = newValue as ICommand; - } - }); - - public static readonly BindableProperty IsRefreshingProperty = - BindableProperty.Create( - nameof(IsRefreshing), - typeof(bool), - typeof(DataGrid), - false, - BindingMode.TwoWay, - propertyChanged: (bindable, oldValue, newValue) => - { - (bindable as DataGrid).DataList.IsRefreshing = (bool)newValue; - }); - - public static readonly BindableProperty BorderThicknessProperty = - BindableProperty.Create( - nameof(BorderThickness), - typeof(Thickness), - typeof(DataGrid), - new Thickness(1), - propertyChanged: (bindable, oldValue, newValue) => - { - (bindable as DataGrid)._headerView.ColumnSpacing = ((Thickness)newValue).HorizontalThickness / 2; - (bindable as DataGrid)._headerView.Padding = ((Thickness)newValue).HorizontalThickness / 2; - }); - - public static readonly BindableProperty HeaderBordersVisibleProperty = - BindableProperty.Create( - nameof(HeaderBordersVisible), - typeof(bool), - typeof(DataGrid), - true, - propertyChanged: (bindable, oldValue, newValue) => (bindable as DataGrid)._headerView.BackgroundColor = (bool)newValue ? (bindable as DataGrid).BorderColor : (bindable as DataGrid).HeaderBackground); - - public static readonly BindableProperty SortedColumnIndexProperty = - BindableProperty.Create( - nameof(SortedColumnIndex), - typeof(SortData), - typeof(DataGrid), - null, - BindingMode.TwoWay, - validateValue: (bindable, v) => - { - var self = bindable as DataGrid; - var sData = (SortData)v; - - return - sData == null || //setted to null - self.Columns == null || // Columns binded but not setted - self.Columns.Count == 0 || //columns not setted yet - (sData.Index < self.Columns.Count && self.Columns.ElementAt(sData.Index).SortingEnabled); - }, - propertyChanged: (bindable, oldValue, newValue) => - { - var self = bindable as DataGrid; - if (oldValue != newValue) - self.SortItems((SortData)newValue); - }); - - - public static readonly BindableProperty HeaderLabelStyleProperty = - BindableProperty.Create(nameof(HeaderLabelStyle), typeof(Style), typeof(DataGrid)); - - public static readonly BindableProperty AscendingIconProperty = - BindableProperty.Create( - nameof(AscendingIcon), - typeof(ImageSource), - typeof(DataGrid), - ImageSource.FromResource("Xamarin.Forms.DataGrid.up.png", - typeof(DataGrid).GetTypeInfo().Assembly)); - - public static readonly BindableProperty DescendingIconProperty = - BindableProperty.Create( - nameof(DescendingIcon), - typeof(ImageSource), - typeof(DataGrid), - ImageSource.FromResource("Xamarin.Forms.DataGrid.down.png", - typeof(DataGrid).GetTypeInfo().Assembly)); - - public static readonly BindableProperty DescendingIconStyleProperty = - BindableProperty.Create(nameof(DescendingIconStyle), typeof(Style), typeof(DataGrid), null, - - propertyChanged: (bindable, oldValue, newValue) => - { - var self = bindable as DataGrid; - var style = (newValue as Style).Setters.FirstOrDefault(x => x.Property == Image.SourceProperty); - if (style != null) - { - if (style.Value is string vs) - self.DescendingIcon = ImageSource.FromFile(vs); - else - self.DescendingIcon = (ImageSource)style.Value; - } - }); - - public static readonly BindableProperty AscendingIconStyleProperty = - BindableProperty.Create(nameof(AscendingIconStyle), typeof(Style), typeof(DataGrid), null, - coerceValue: (bindable, v) => - { - var self = bindable as DataGrid; - - return v; - }, - - propertyChanged: (bindable, oldValue, newValue) => - { - var self = bindable as DataGrid; - if ((newValue as Style).Setters.Any(x => x.Property == Image.SourceProperty)) - { - var style = (newValue as Style).Setters.FirstOrDefault(x => x.Property == Image.SourceProperty); - if (style != null) - { - if (style.Value is string vs) - self.AscendingIcon = ImageSource.FromFile(vs); - else - self.AscendingIcon = (ImageSource)style.Value; - } - } - }); - - public static readonly BindableProperty NoDataViewProperty = - BindableProperty.Create(nameof(NoDataView), typeof(View), typeof(DataGrid), - propertyChanged: (bindable, oldValue, newValue) => - { - if (oldValue != newValue) - (bindable as DataGrid)._noDataView.Content = newValue as View; - }); - #endregion - - #region Properties - public Color ActiveRowColor - { - get { return (Color)GetValue(ActiveRowColorProperty); } - set { SetValue(ActiveRowColorProperty, value); } - } - - public Color HeaderBackground - { - get { return (Color)GetValue(HeaderBackgroundProperty); } - set { SetValue(HeaderBackgroundProperty, value); } - } - - [Obsolete("Please use HeaderLabelStyle", true)] - public Color HeaderTextColor - { - get; set; - } - - public Color BorderColor - { - get { return (Color)GetValue(BorderColorProperty); } - set { SetValue(BorderColorProperty, value); } - } - - public IColorProvider RowsBackgroundColorPalette - { - get { return (IColorProvider)GetValue(RowsBackgroundColorPaletteProperty); } - set { SetValue(RowsBackgroundColorPaletteProperty, value); } - } - - public IColorProvider RowsTextColorPalette - { - get { return (IColorProvider)GetValue(RowsTextColorPaletteProperty); } - set { SetValue(RowsTextColorPaletteProperty, value); } - } - - public IEnumerable ItemsSource - { - get { return (IEnumerable)GetValue(ItemsSourceProperty); } - set { SetValue(ItemsSourceProperty, value); } - } - - internal ObservableCollection InternalItems - { - get { return _internalItems; } - set - { - if (value != _internalItems) - { - _internalItems = value; - if (IsSortable && SortedColumnIndex != null) - { - SortItems(SortedColumnIndex); - } - } - DataList.ItemsSource = _internalItems; - } - } - - public ColumnCollection Columns - { - get { return (ColumnCollection)GetValue(ColumnsProperty); } - set { SetValue(ColumnsProperty, value); } - } - - public double FontSize - { - get { return (double)GetValue(FontSizeProperty); } - set { SetValue(FontSizeProperty, value); } - } - - [Obsolete("Please use HeaderLabelStyle", true)] - public double HeaderFontSize - { - get; set; - } - - public string FontFamily - { - get { return (string)GetValue(FontFamilyProperty); } - set { SetValue(FontFamilyProperty, value); } - } - - public int RowHeight - { - get { return (int)GetValue(RowHeightProperty); } - set { SetValue(RowHeightProperty, value); } - } - - public int HeaderHeight - { - get { return (int)GetValue(HeaderHeightProperty); } - set { SetValue(HeaderHeightProperty, value); } - } - - public bool IsSortable - { - get { return (bool)GetValue(IsSortableProperty); } - set { SetValue(IsSortableProperty, value); } - } - - public bool SelectionEnabled - { - get { return (bool)GetValue(SelectionEnabledProperty); } - set { SetValue(SelectionEnabledProperty, value); } - } - - public object SelectedItem - { - get { return GetValue(SelectedItemProperty); } - set { SetValue(SelectedItemProperty, value); } - } - - public ICommand PullToRefreshCommand - { - get { return (ICommand)GetValue(PullToRefreshCommandProperty); } - set { SetValue(PullToRefreshCommandProperty, value); } - } - - public bool IsRefreshing - { - get { return (bool)GetValue(IsRefreshingProperty); } - set { SetValue(IsRefreshingProperty, value); } - } - - public Thickness BorderThickness - { - get { return (Thickness)GetValue(BorderThicknessProperty); } - set { SetValue(BorderThicknessProperty, value); } - } - - public bool HeaderBordersVisible - { - get { return (bool)GetValue(HeaderBordersVisibleProperty); } - set { SetValue(HeaderBordersVisibleProperty, value); } - } - - public SortData SortedColumnIndex - { - get { return (SortData)GetValue(SortedColumnIndexProperty); } - set { SetValue(SortedColumnIndexProperty, value); } - } - - public Style HeaderLabelStyle - { - get { return (Style)GetValue(HeaderLabelStyleProperty); } - set { SetValue(HeaderLabelStyleProperty, value); } - } - - public ImageSource AscendingIcon - { - get { return (ImageSource)GetValue(AscendingIconProperty); } - set { SetValue(AscendingIconProperty, value); } - } - - public ImageSource DescendingIcon - { - get { return (ImageSource)GetValue(DescendingIconProperty); } - set { SetValue(DescendingIconProperty, value); } - } - - public Style AscendingIconStyle - { - get { return (Style)GetValue(AscendingIconStyleProperty); } - set { SetValue(AscendingIconStyleProperty, value); } - } - - public Style DescendingIconStyle - { - get { return (Style)GetValue(DescendingIconStyleProperty); } - set { SetValue(DescendingIconStyleProperty, value); } - } - - public View NoDataView - { - get { return (View)GetValue(NoDataViewProperty); } - set { SetValue(NoDataViewProperty, value); } - } - #endregion - - #region UI Methods - protected override void OnParentSet() - { - base.OnParentSet(); - InitHeaderView(); - } - - protected override void OnBindingContextChanged() - { - base.OnBindingContextChanged(); - SetColumnsBindingContext(); - } - - #endregion - - #region Private Methods - - private void Reload() - { - InternalItems = new ObservableCollection(_internalItems); - } - private void SortItems(SortData sData) - { - if (InternalItems == null || sData.Index >= Columns.Count || !Columns[sData.Index].SortingEnabled) - return; - - var items = InternalItems; - var column = Columns[sData.Index]; - SortingOrder order = sData.Order; - - if (!IsSortable) - throw new InvalidOperationException("This DataGrid is not sortable"); - else if (column.PropertyName == null) - 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(); - - column.SortingIcon.Style = (order == SortingOrder.Descendant) ? - AscendingIconStyle ?? (Style)_headerView.Resources["DescendingIconStyle"] : - DescendingIconStyle ?? (Style)_headerView.Resources["AscendingIconStyle"]; - - //Support DescendingIcon property (if setted) - if (!column.SortingIcon.Style.Setters.Any(x => x.Property == Image.SourceProperty)) - { - if (order == SortingOrder.Descendant && DescendingIconProperty.DefaultValue != DescendingIcon) - column.SortingIcon.Source = DescendingIcon; - if (order == SortingOrder.Ascendant && AscendingIconProperty.DefaultValue != AscendingIcon) - column.SortingIcon.Source = AscendingIcon; - } - - for (int i = 0; i < Columns.Count; i++) - { - if (i != sData.Index) - { - if (Columns[i].SortingIcon.Style != null) - Columns[i].SortingIcon.Style = null; - if (Columns[i].SortingIcon.Source != null) - Columns[i].SortingIcon.Source = null; - _sortingOrders[i] = SortingOrder.None; - } - } - - _internalItems = items; - - _sortingOrders[sData.Index] = order; - SortedColumnIndex = sData; - } - - private View GetHeaderViewForColumn(DataGridColumn column) - { - column.HeaderLabel.Style = column.HeaderLabelStyle ?? this.HeaderLabelStyle ?? (Style)_headerView.Resources["HeaderDefaultStyle"]; - - Grid grid = new Grid - { - ColumnSpacing = 0, - }; - - grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) }); - grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Auto) }); - - if (IsSortable) - { - column.SortingIcon.Style = (Style)_headerView.Resources["ImageStyleBase"]; - - grid.Children.Add(column.SortingIcon); - Grid.SetColumn(column.SortingIcon, 1); - - TapGestureRecognizer tgr = new TapGestureRecognizer(); - tgr.Tapped += (s, e) => - { - int index = Columns.IndexOf(column); - SortingOrder order = _sortingOrders[index] == SortingOrder.Ascendant ? SortingOrder.Descendant : SortingOrder.Ascendant; - - if (Columns.ElementAt(index).SortingEnabled) - SortedColumnIndex = new SortData(index, order); - }; - grid.GestureRecognizers.Add(tgr); - } - - grid.Children.Add(column.HeaderLabel); - - return grid; - } - - private void InitHeaderView() - { - SetColumnsBindingContext(); - _headerView.Children.Clear(); - _headerView.ColumnDefinitions.Clear(); - _sortingOrders.Clear(); - - _headerView.Padding = new Thickness(BorderThickness.Left, BorderThickness.Top, BorderThickness.Right, 0); - _headerView.ColumnSpacing = BorderThickness.HorizontalThickness / 2; - - if (Columns != null) - { - foreach (var col in Columns) - { - _headerView.ColumnDefinitions.Add(new ColumnDefinition { Width = col.Width }); - - var cell = GetHeaderViewForColumn(col); - - _headerView.Children.Add(cell); - Grid.SetColumn(cell, Columns.IndexOf(col)); - - _sortingOrders.Add(Columns.IndexOf(col), SortingOrder.None); - } - } - } - - private void SetColumnsBindingContext() - { - if (Columns != null) - foreach (var c in Columns) - c.BindingContext = BindingContext; - } - - #endregion Private Methods - } -} diff --git a/aurora-sharp-desktop/Aurora/Design/Components/DataGrid/DataGridColumn.cs b/aurora-sharp-desktop/Aurora/Design/Components/DataGrid/DataGridColumn.cs deleted file mode 100644 index 59d2ab5..0000000 --- a/aurora-sharp-desktop/Aurora/Design/Components/DataGrid/DataGridColumn.cs +++ /dev/null @@ -1,135 +0,0 @@ -using System; -using Xamarin.Forms; - -namespace Aurora.Design.Components.DataGrid -{ - public class DataGridColumn : BindableObject, IDefinition - { - #region bindable properties - public static readonly BindableProperty WidthProperty = - BindableProperty.Create(nameof(Width), typeof(GridLength), typeof(DataGridColumn), new GridLength(1, GridUnitType.Star), - propertyChanged: (bindable, oldValue, newValue) => - { - if (oldValue != newValue) - { - (bindable as DataGridColumn).OnSizeChanged(); - }; - }); - - public static readonly BindableProperty TitleProperty = - BindableProperty.Create(nameof(Title), typeof(string), typeof(DataGridColumn), string.Empty, - propertyChanged: (b, o, n) => (b as DataGridColumn).HeaderLabel.Text = (string)n); - - public static readonly BindableProperty FormattedTitleProperty = - BindableProperty.Create(nameof(FormattedTitle), typeof(FormattedString), typeof(DataGridColumn), - propertyChanged: (b, o, n) => (b as DataGridColumn).HeaderLabel.FormattedText = (FormattedString)n); - - public static readonly BindableProperty PropertyNameProperty = - BindableProperty.Create(nameof(PropertyName), typeof(string), typeof(DataGridColumn), null); - - public static readonly BindableProperty StringFormatProperty = - BindableProperty.Create(nameof(StringFormat), typeof(string), typeof(DataGridColumn), null); - - public static readonly BindableProperty CellTemplateProperty = - BindableProperty.Create(nameof(CellTemplate), typeof(DataTemplate), typeof(DataGridColumn), null); - - public static readonly BindableProperty HorizontalContentAlignmentProperty = - BindableProperty.Create(nameof(HorizontalContentAlignment), typeof(LayoutOptions), typeof(DataGridColumn), LayoutOptions.Center); - - public static readonly BindableProperty VerticalContentAlignmentProperty = - BindableProperty.Create(nameof(VerticalContentAlignment), typeof(LayoutOptions), typeof(DataGridColumn), LayoutOptions.Center); - - public static readonly BindableProperty SortingEnabledProperty = - BindableProperty.Create(nameof(SortingEnabled), typeof(bool), typeof(DataGridColumn), true); - - public static readonly BindableProperty HeaderLabelStyleProperty = - BindableProperty.Create(nameof(HeaderLabelStyle), typeof(Style), typeof(DataGridColumn), - propertyChanged: (b, o, n) => - { - if ((b as DataGridColumn).HeaderLabel != null && (o != n)) - (b as DataGridColumn).HeaderLabel.Style = n as Style; - }); - - #endregion - - #region properties - - public GridLength Width - { - get { return (GridLength)GetValue(WidthProperty); } - set { SetValue(WidthProperty, value); } - } - - public string Title - { - get { return (string)GetValue(TitleProperty); } - set { SetValue(TitleProperty, value); } - } - - public FormattedString FormattedTitle - { - get { return (string)GetValue(FormattedTitleProperty); } - set { SetValue(FormattedTitleProperty, value); } - } - public string PropertyName - { - get { return (string)GetValue(PropertyNameProperty); } - set { SetValue(PropertyNameProperty, value); } - } - - public string StringFormat - { - get { return (string)GetValue(StringFormatProperty); } - set { SetValue(StringFormatProperty, value); } - } - - public DataTemplate CellTemplate - { - get { return (DataTemplate)GetValue(CellTemplateProperty); } - set { SetValue(CellTemplateProperty, value); } - } - - internal Image SortingIcon { get; set; } - internal Label HeaderLabel { get; set; } - - public LayoutOptions HorizontalContentAlignment - { - get { return (LayoutOptions)GetValue(HorizontalContentAlignmentProperty); } - set { SetValue(HorizontalContentAlignmentProperty, value); } - } - - public LayoutOptions VerticalContentAlignment - { - get { return (LayoutOptions)GetValue(VerticalContentAlignmentProperty); } - set { SetValue(VerticalContentAlignmentProperty, value); } - } - - public bool SortingEnabled - { - get { return (bool)GetValue(SortingEnabledProperty); } - set { SetValue(SortingEnabledProperty, value); } - } - - public Style HeaderLabelStyle - { - get { return (Style)GetValue(HeaderLabelStyleProperty); } - set { SetValue(HeaderLabelStyleProperty, value); } - } - - #endregion - - public event EventHandler SizeChanged; - - public DataGridColumn() - { - HeaderLabel = new Label(); - SortingIcon = new Image(); - } - - void OnSizeChanged() - { - SizeChanged?.Invoke(this, EventArgs.Empty); - } - } - -} diff --git a/aurora-sharp-desktop/Aurora/Design/Components/DataGrid/DataGridRowTemplateSelector.cs b/aurora-sharp-desktop/Aurora/Design/Components/DataGrid/DataGridRowTemplateSelector.cs deleted file mode 100644 index b27648b..0000000 --- a/aurora-sharp-desktop/Aurora/Design/Components/DataGrid/DataGridRowTemplateSelector.cs +++ /dev/null @@ -1,30 +0,0 @@ -using Xamarin.Forms; -namespace Aurora.Design.Components.DataGrid -{ - internal class DataGridRowTemplateSelector : DataTemplateSelector - { - private static DataTemplate _dataGridRowTemplate; - - public DataGridRowTemplateSelector() - { - _dataGridRowTemplate = new DataTemplate(typeof(DataGridViewCell)); - } - - protected override DataTemplate OnSelectTemplate(object item, BindableObject container) - { - 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-sharp-desktop/Aurora/Design/Components/DataGrid/DataGridViewCell.cs b/aurora-sharp-desktop/Aurora/Design/Components/DataGrid/DataGridViewCell.cs deleted file mode 100644 index 7ba1c1f..0000000 --- a/aurora-sharp-desktop/Aurora/Design/Components/DataGrid/DataGridViewCell.cs +++ /dev/null @@ -1,163 +0,0 @@ -using Xamarin.Forms; -namespace Aurora.Design.Components.DataGrid -{ - internal sealed class DataGridViewCell : ViewCell - { - #region Fields - Grid _mainLayout; - Color _bgColor; - Color _textColor; - bool _hasSelected; - #endregion - - #region properties - public DataGrid DataGrid - { - get { return (DataGrid)GetValue(DataGridProperty); } - set { SetValue(DataGridProperty, value); } - } - - public int Index - { - get { return (int)GetValue(IndexProperty); } - set { SetValue(IndexProperty, value); } - } - - public object RowContext - { - get { return GetValue(RowContextProperty); } - set { SetValue(RowContextProperty, value); } - } - #endregion - - #region Bindable Properties - public static readonly BindableProperty DataGridProperty = - 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, - propertyChanged: (b, o, n) => (b as DataGridViewCell).UpdateBackgroundColor()); - - public static readonly BindableProperty RowContextProperty = - BindableProperty.Create( - nameof(RowContext), - typeof(object), - typeof(DataGridViewCell), - propertyChanged: (b, o, n) => (b as DataGridViewCell).UpdateBackgroundColor()); - #endregion - - #region Methods - private void CreateView() - { - UpdateBackgroundColor(); - - _mainLayout = new Grid() - { - BackgroundColor = DataGrid.BorderColor, - RowSpacing = 0, - ColumnSpacing = DataGrid.BorderThickness.HorizontalThickness / 2, - Padding = new Thickness(DataGrid.BorderThickness.HorizontalThickness / 2, - DataGrid.BorderThickness.VerticalThickness / 2), - }; - - foreach (var col in DataGrid.Columns) - { - _mainLayout.ColumnDefinitions.Add(new ColumnDefinition() { Width = col.Width }); - View cell; - - if (col.CellTemplate != null) - { - cell = new ContentView() { Content = col.CellTemplate.CreateContent() as View }; - if (col.PropertyName != null) - { - cell.SetBinding(BindingContextProperty, - new Binding(col.PropertyName, source: RowContext)); - } - } - else - { - var text = new Label - { - TextColor = _textColor, - HorizontalOptions = col.HorizontalContentAlignment, - VerticalOptions = col.VerticalContentAlignment, - LineBreakMode = LineBreakMode.WordWrap, - }; - text.SetBinding(Label.TextProperty, new Binding(col.PropertyName, BindingMode.Default, stringFormat: col.StringFormat)); - text.SetBinding(Label.FontSizeProperty, new Binding(DataGrid.FontSizeProperty.PropertyName, BindingMode.Default, source: DataGrid)); - text.SetBinding(Label.FontFamilyProperty, new Binding(DataGrid.FontFamilyProperty.PropertyName, BindingMode.Default, source: DataGrid)); - - cell = new ContentView - { - Padding = 0, - BackgroundColor = _bgColor, - Content = text, - }; - } - - _mainLayout.Children.Add(cell); - Grid.SetColumn(cell, DataGrid.Columns.IndexOf(col)); - } - - View = _mainLayout; - } - - private void UpdateBackgroundColor() - { - _hasSelected = DataGrid.SelectedItem == RowContext; - int actualIndex = DataGrid?.InternalItems?.IndexOf(BindingContext) ?? -1; - if (actualIndex > -1) - { - _bgColor = (DataGrid.SelectionEnabled && DataGrid.SelectedItem != null && DataGrid.SelectedItem == RowContext) ? - DataGrid.ActiveRowColor : DataGrid.RowsBackgroundColorPalette.GetColor(Index, BindingContext); - _textColor = DataGrid.RowsTextColorPalette.GetColor(actualIndex, BindingContext); - - ChangeColor(_bgColor); - } - } - - private void ChangeColor(Color color) - { - foreach (var v in _mainLayout.Children) - { - v.BackgroundColor = color; - var contentView = v as ContentView; - if (contentView?.Content is Label) - ((Label)contentView.Content).TextColor = _textColor; - } - } - - protected override void OnBindingContextChanged() - { - base.OnBindingContextChanged(); - UpdateBackgroundColor(); - } - - protected override void OnParentSet() - { - base.OnParentSet(); - if (Parent != null) - DataGrid.ItemSelected += DataGrid_ItemSelected; - else - DataGrid.ItemSelected -= DataGrid_ItemSelected; - } - - private void DataGrid_ItemSelected(object sender, SelectedItemChangedEventArgs e) - { - if (DataGrid.SelectionEnabled && (e.SelectedItem == RowContext || _hasSelected)) - { - UpdateBackgroundColor(); - } - } - #endregion - } -} diff --git a/aurora-sharp-desktop/Aurora/Design/Components/DataGrid/IColorProvider.cs b/aurora-sharp-desktop/Aurora/Design/Components/DataGrid/IColorProvider.cs deleted file mode 100644 index 3cc9825..0000000 --- a/aurora-sharp-desktop/Aurora/Design/Components/DataGrid/IColorProvider.cs +++ /dev/null @@ -1,8 +0,0 @@ -using Xamarin.Forms; -namespace Aurora.Design.Components.DataGrid -{ - public interface IColorProvider - { - Color GetColor(int rowIndex, object item); - } -} diff --git a/aurora-sharp-desktop/Aurora/Design/Components/DataGrid/PaletteCollection.cs b/aurora-sharp-desktop/Aurora/Design/Components/DataGrid/PaletteCollection.cs deleted file mode 100644 index 770c8d9..0000000 --- a/aurora-sharp-desktop/Aurora/Design/Components/DataGrid/PaletteCollection.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using Xamarin.Forms; - -namespace Aurora.Design.Components.DataGrid -{ - public sealed class PaletteCollection : List, IColorProvider - { - public Color GetColor(int rowIndex, object item) - { - if (Count > 0) - return this.ElementAt(rowIndex % Count); - else - return default(Color); - } - } -} diff --git a/aurora-sharp-desktop/Aurora/Design/Components/DataGrid/SortData.cs b/aurora-sharp-desktop/Aurora/Design/Components/DataGrid/SortData.cs deleted file mode 100644 index 1552d09..0000000 --- a/aurora-sharp-desktop/Aurora/Design/Components/DataGrid/SortData.cs +++ /dev/null @@ -1,51 +0,0 @@ -using System; -using Xamarin.Forms; - -namespace Aurora.Design.Components.DataGrid -{ - - [TypeConverter(typeof(SortDataTypeConverter))] - public class SortData - { - - #region ctor - public SortData() - { - } - - public SortData(int index, SortingOrder order) - { - Index = index; - Order = order; - } - - #endregion - - #region Properties - public SortingOrder Order { get; set; } - - public int Index { get; set; } - #endregion - - public static implicit operator SortData(int index) - { - return new SortData - { - Index = Math.Abs(index), - Order = index < 0 ? SortingOrder.Descendant : SortingOrder.Ascendant - }; - } - - public override bool Equals(object obj) - { - if (obj is SortData) - { - SortData other = obj as SortData; - return other.Index == Index && other.Order == Order; - } - else - return false; - } - - } -} diff --git a/aurora-sharp-desktop/Aurora/Design/Components/DataGrid/SortDataTypeConverter.cs b/aurora-sharp-desktop/Aurora/Design/Components/DataGrid/SortDataTypeConverter.cs deleted file mode 100644 index baf0d0d..0000000 --- a/aurora-sharp-desktop/Aurora/Design/Components/DataGrid/SortDataTypeConverter.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; -using Xamarin.Forms; - -namespace Aurora.Design.Components.DataGrid -{ - public class SortDataTypeConverter : TypeConverter - { - - public override bool CanConvertFrom(Type sourceType) - { - return base.CanConvertFrom(sourceType); - } - - public override object ConvertFromInvariantString(string value) - { - int index = 0; - - if (int.TryParse(value, out index)) - return (SortData)index; - else - return null; - } - } -} diff --git a/aurora-sharp-desktop/Aurora/Design/Components/DataGrid/SortingOrder.cs b/aurora-sharp-desktop/Aurora/Design/Components/DataGrid/SortingOrder.cs deleted file mode 100644 index 78c9520..0000000 --- a/aurora-sharp-desktop/Aurora/Design/Components/DataGrid/SortingOrder.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace Aurora.Design.Components.DataGrid -{ - public enum SortingOrder - { - None = 0, - Ascendant = 1, - Descendant = 2, - } -} diff --git a/aurora-sharp-desktop/Aurora/Design/Components/DataGrid/down.png b/aurora-sharp-desktop/Aurora/Design/Components/DataGrid/down.png deleted file mode 100644 index 3a359e8..0000000 Binary files a/aurora-sharp-desktop/Aurora/Design/Components/DataGrid/down.png and /dev/null differ diff --git a/aurora-sharp-desktop/Aurora/Design/Components/DataGrid/up.png b/aurora-sharp-desktop/Aurora/Design/Components/DataGrid/up.png deleted file mode 100644 index bd675ae..0000000 Binary files a/aurora-sharp-desktop/Aurora/Design/Components/DataGrid/up.png and /dev/null differ diff --git a/aurora-sharp-desktop/Aurora/Design/Components/Library/Library.xaml b/aurora-sharp-desktop/Aurora/Design/Components/Library/Library.xaml index 8c06a8c..e4fe912 100644 --- a/aurora-sharp-desktop/Aurora/Design/Components/Library/Library.xaml +++ b/aurora-sharp-desktop/Aurora/Design/Components/Library/Library.xaml @@ -2,7 +2,7 @@