From 3d276285b4dd17b5f8e59483e0b2c3b677216a37 Mon Sep 17 00:00:00 2001 From: akgulebubekir Date: Thu, 6 Apr 2017 14:18:40 +0300 Subject: [PATCH] FormattedTitle feature added --- .../DataGridSample/Views/MainPage.xaml | 103 ++++++++++-------- Xamarin.Forms.DataGrid/DataGrid.xaml.cs | 35 +++--- Xamarin.Forms.DataGrid/DataGridColumn.cs | 18 ++- 3 files changed, 86 insertions(+), 70 deletions(-) diff --git a/DataGridSample/DataGridSample/Views/MainPage.xaml b/DataGridSample/DataGridSample/Views/MainPage.xaml index 765868d..38e6ede 100644 --- a/DataGridSample/DataGridSample/Views/MainPage.xaml +++ b/DataGridSample/DataGridSample/Views/MainPage.xaml @@ -6,56 +6,63 @@ xmlns:dg="clr-namespace:Xamarin.Forms.DataGrid;assembly=Xamarin.Forms.DataGrid" xmlns:conv="clr-namespace:DataGridSample.Views.Converters;assembly=DataGridSample" > - + - - - - 15 - 12 - - - - - - - - - - - - - - - - - - - - - - - - - - - #F2F2F2 - #FFFFFF - - - - - - - - - + + + + 15 + 12 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + #F2F2F2 + #FFFFFF + + + + + + + + + diff --git a/Xamarin.Forms.DataGrid/DataGrid.xaml.cs b/Xamarin.Forms.DataGrid/DataGrid.xaml.cs index 0c4e053..2e6dd5a 100644 --- a/Xamarin.Forms.DataGrid/DataGrid.xaml.cs +++ b/Xamarin.Forms.DataGrid/DataGrid.xaml.cs @@ -71,15 +71,15 @@ public partial class DataGrid : Grid self.InternalItems = new List(((IEnumerable)n).Cast()); } - - 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; - } - + + 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; + } + }); void HandleItemsSourceCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) @@ -182,7 +182,7 @@ void HandleItemsSourceCollectionChanged(object sender, NotifyCollectionChangedEv }); #endregion - #region properties + #region Properties public Color ActiveRowColor { get { return (Color)GetValue(ActiveRowColorProperty); } @@ -364,7 +364,7 @@ public View NoDataView } #endregion - #region fields + #region Fields Dictionary _sortingOrders; @@ -402,15 +402,11 @@ protected override void OnParentSet() } #endregion - #region header creation methods + #region Header Creation Methods private View GetHeaderViewForColumn(DataGridColumn column) { - column.HeaderLabel = new Label - { - Text = column.Title, - Style = column.HeaderLabelStyle ?? this.HeaderLabelStyle ?? (Style)_headerView.Resources["HeaderDefaultStyle"] - }; + column.HeaderLabel.Style = column.HeaderLabelStyle ?? this.HeaderLabelStyle ?? (Style)_headerView.Resources["HeaderDefaultStyle"]; Grid grid = new Grid { @@ -422,10 +418,7 @@ private View GetHeaderViewForColumn(DataGridColumn column) if (IsSortable) { - column.SortingIcon = new Image - { - Style = (Style)_headerView.Resources["ImageStyleBase"], - }; + column.SortingIcon.Style = (Style)_headerView.Resources["ImageStyleBase"]; grid.Children.Add(column.SortingIcon); Grid.SetColumn(column.SortingIcon, 1); diff --git a/Xamarin.Forms.DataGrid/DataGridColumn.cs b/Xamarin.Forms.DataGrid/DataGridColumn.cs index 7130998..ab3b3ca 100644 --- a/Xamarin.Forms.DataGrid/DataGridColumn.cs +++ b/Xamarin.Forms.DataGrid/DataGridColumn.cs @@ -10,7 +10,12 @@ public class DataGridColumn : BindableObject, IDefinition propertyChanged: (b, o, n) => { if (o != n) (b as DataGridColumn).OnSizeChanged(); }); public static readonly BindableProperty TitleProperty = - BindableProperty.Create(nameof(Title), typeof(string), typeof(DataGridColumn), string.Empty); + 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); @@ -54,6 +59,11 @@ public string Title set { SetValue(TitleProperty, value); } } + public FormattedString FormattedTitle + { + get { return (string)GetValue(FormattedTitleProperty); } + set { SetValue(FormattedTitleProperty, value); } + } public string PropertyName { get { return (string)GetValue(PropertyNameProperty); } @@ -103,6 +113,12 @@ public Style HeaderLabelStyle public event EventHandler SizeChanged; + public DataGridColumn() + { + HeaderLabel = new Label(); + SortingIcon = new Image(); + } + void OnSizeChanged() { SizeChanged?.Invoke(this, EventArgs.Empty);