diff --git a/Aurora/Design/Components/DataGrid/DataGrid.xaml b/Aurora/Design/Components/DataGrid/DataGrid.xaml
index 3ec3f45..d6ae78c 100644
--- a/Aurora/Design/Components/DataGrid/DataGrid.xaml
+++ b/Aurora/Design/Components/DataGrid/DataGrid.xaml
@@ -87,7 +87,7 @@
-
+
_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: (b, v) =>
+ BindableProperty.Create(
+ nameof(ActiveRowColor),
+ typeof(Color),
+ typeof(DataGrid),
+ Color.FromRgb(128, 144, 160),
+ coerceValue: (bindable, value) =>
{
- if (!(b as DataGrid).SelectionEnabled)
+ if (!(bindable as DataGrid).SelectionEnabled)
throw new InvalidOperationException("Datagrid must be SelectionEnabled=true to set ActiveRowColor");
- return v;
+ return value;
});
public static readonly BindableProperty HeaderBackgroundProperty =
- BindableProperty.Create(nameof(HeaderBackground), typeof(Color), typeof(DataGrid), Color.White,
- propertyChanged: (b, o, n) =>
+ BindableProperty.Create(
+ nameof(HeaderBackground),
+ typeof(Color),
+ typeof(DataGrid),
+ Color.White,
+ propertyChanged: (bindable, oldValue, newValue) =>
{
- var self = b as DataGrid;
+ var self = bindable as DataGrid;
if (self._headerView != null && !self.HeaderBordersVisible)
- self._headerView.BackgroundColor = (Color)n;
+ self._headerView.BackgroundColor = (Color)newValue;
});
public static readonly BindableProperty BorderColorProperty =
- BindableProperty.Create(nameof(BorderColor), typeof(Color), typeof(DataGrid), Color.Black,
- propertyChanged: (b, o, n) =>
+ BindableProperty.Create(
+ nameof(BorderColor),
+ typeof(Color),
+ typeof(DataGrid),
+ Color.Black,
+ propertyChanged: (bindable, oldValue, newValue) =>
{
- var self = b as DataGrid;
+ var self = bindable as DataGrid;
if (self.HeaderBordersVisible)
- self._headerView.BackgroundColor = (Color)n;
+ 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: (b, o, n) =>
+ BindableProperty.Create(nameof(RowsBackgroundColorPalette),
+ typeof(IColorProvider),
+ typeof(DataGrid),
+ new PaletteCollection { default(Color) },
+ propertyChanged: (bindable, oldValue, newValue) =>
{
- var self = b as DataGrid;
+ 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: (b, o, n) =>
+ BindableProperty.Create(
+ nameof(RowsTextColorPalette),
+ typeof(IColorProvider),
+ typeof(DataGrid),
+ new PaletteCollection { Color.Black },
+ propertyChanged: (bindable, oldValue, newValue) =>
{
- var self = b as DataGrid;
+ 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: (b, o, n) => (b as DataGrid).InitHeaderView(),
- defaultValueCreator: b => { return new ColumnCollection(); }
+ BindableProperty.Create(
+ nameof(Columns),
+ typeof(ColumnCollection),
+ typeof(DataGrid),
+ propertyChanged: (bindable, oldValue, newValue) =>
+ {
+ (bindable as DataGrid).InitHeaderView();
+ },
+ defaultValueCreator: bindable => { return new ColumnCollection(); }
);
- public static readonly BindableProperty ItemsSourceProperty =
- BindableProperty.Create(nameof(ItemsSource), typeof(IEnumerable), typeof(DataGrid), null,
- propertyChanged: (b, o, n) =>
+ public static BindableProperty ItemsSourceProperty =
+ BindableProperty.Create(
+ propertyName: nameof(ItemsSource),
+ returnType: typeof(IEnumerable),
+ declaringType: typeof(DataGrid),
+ defaultBindingMode: BindingMode.TwoWay,
+ propertyChanged: (bindable, oldValue, newValue) =>
{
- DataGrid self = b as DataGrid;
+ DataGrid self = bindable as DataGrid;
//ObservableCollection Tracking
- if (o != null && o is INotifyCollectionChanged)
- (o as INotifyCollectionChanged).CollectionChanged -= self.HandleItemsSourceCollectionChanged;
-
- if (n != null)
+ if (oldValue != null && oldValue is INotifyCollectionChanged)
{
- if (n is INotifyCollectionChanged)
- (n as INotifyCollectionChanged).CollectionChanged += self.HandleItemsSourceCollectionChanged;
+ (oldValue as INotifyCollectionChanged).CollectionChanged -= self.HandleItemsSourceCollectionChanged;
+ }
- self.InternalItems = new List
\ No newline at end of file