Merge pull request #311 from telerik/Nasko/nestedgrid-improvements

Improve the property of the DataGrid for subscribing to property chan…
This commit is contained in:
Atanas Popatanasov 2018-08-23 16:04:25 +03:00 коммит произвёл GitHub
Родитель 03ae84f5fc 735cfb32a1
Коммит a04d192053
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
8 изменённых файлов: 68 добавлений и 69 удалений

Просмотреть файл

@ -61,6 +61,14 @@ namespace Telerik.Data.Core
foreach (var item in collectionView)
{
if (!this.supportsPropertyChangedInitialized)
{
this.itemSupportsPropertyChanged = item is INotifyPropertyChanged;
this.supportsPropertyChangedInitialized = true;
}
this.AddPropertyChangedHandler(item);
if (!isSourceGrouped)
{
this.internalList.Add(item);
@ -185,7 +193,7 @@ namespace Telerik.Data.Core
{
string propertyName = ((PropertyChangedEventArgs)args).PropertyName;
NestedPropertyInfo info;
if (this.nestedObjectInfos.TryGetValue(sender, out info))
if (this.nestedObjectInfos != null && this.nestedObjectInfos.TryGetValue(sender, out info))
{
this.NestedPropertyChanged(sender, info.rootItems, propertyName, info.nestedPropertyPath);
PropertyChangedEventArgs arguments = new PropertyChangedEventArgs(info.nestedPropertyPath + propertyName);
@ -197,7 +205,7 @@ namespace Telerik.Data.Core
}
else
{
if (this.nestedObjectInfos.Count > 0)
if (this.nestedObjectInfos != null && this.nestedObjectInfos.Count > 0)
{
this.NestedPropertyChanged(sender, new HashSet<object> { sender }, propertyName);
}
@ -209,7 +217,7 @@ namespace Telerik.Data.Core
}
}
void IDataSourceView.SubscribeToItemPropertyChanged()
void IDataSourceView.SubscribeToNestedItemPropertyChanged()
{
this.shouldSubsribeToPropertyChanged = true;
if (this.nestedObjectInfos == null)
@ -220,17 +228,14 @@ namespace Telerik.Data.Core
for (int i = 0; i < this.internalList.Count; i++)
{
object item = this.internalList[i];
this.RemovePropertyChangedHandler(item);
this.SubscribeToINotifyPropertyChanged(item, item, string.Empty);
}
}
void IDataSourceView.UnsubscribeFromItemPropertyChanged()
void IDataSourceView.UnsubscribeFromNestedItemPropertyChanged()
{
this.shouldSubsribeToPropertyChanged = false;
foreach (var item in this.internalList)
{
this.RemovePropertyChangedHandler(item);
}
if (this.nestedObjectInfos != null)
{
@ -240,6 +245,7 @@ namespace Telerik.Data.Core
}
this.nestedObjectInfos.Clear();
this.nestedObjectInfos = null;
}
}
@ -453,16 +459,13 @@ namespace Telerik.Data.Core
{
this.internalList.Insert(newIndex, newItem);
if (this.shouldSubsribeToPropertyChanged)
if (this.shouldSubsribeToPropertyChanged && this.nestedObjectInfos != null && this.nestedObjectInfos.Count > 0)
{
if (this.nestedObjectInfos != null && this.nestedObjectInfos.Count > 0)
{
this.SubscribeToINotifyPropertyChanged(newItem, newItem, string.Empty);
}
else
{
this.AddPropertyChangedHandler(newItem);
}
this.SubscribeToINotifyPropertyChanged(newItem, newItem, string.Empty);
}
else
{
this.AddPropertyChangedHandler(newItem);
}
}
@ -494,16 +497,13 @@ namespace Telerik.Data.Core
{
this.internalList[index] = newItem;
if (this.shouldSubsribeToPropertyChanged)
if (this.shouldSubsribeToPropertyChanged && this.nestedObjectInfos != null && this.nestedObjectInfos.Count > 0)
{
if (this.nestedObjectInfos != null && this.nestedObjectInfos.Count > 0)
{
this.SubscribeToINotifyPropertyChanged(newItem, newItem, string.Empty);
}
else
{
this.AddPropertyChangedHandler(newItem);
}
this.SubscribeToINotifyPropertyChanged(newItem, newItem, string.Empty);
}
else
{
this.AddPropertyChangedHandler(newItem);
}
}
@ -515,7 +515,7 @@ namespace Telerik.Data.Core
this.supportsPropertyChangedInitialized = true;
}
if (this.itemSupportsPropertyChanged && this.shouldSubsribeToPropertyChanged)
if (this.itemSupportsPropertyChanged)
{
this.propertyChangedEventHandler.Subscribe(item);
}

Просмотреть файл

@ -42,6 +42,13 @@ namespace Telerik.Data.Core
foreach (var item in enumerableSource)
{
if (!this.supportsPropertyChangedInitialized)
{
this.itemSupportsPropertyChanged = item is INotifyPropertyChanged;
this.supportsPropertyChangedInitialized = true;
}
this.AddPropertyChangedHandler(item);
this.internalList.Add(item);
}
@ -124,7 +131,7 @@ namespace Telerik.Data.Core
{
string propertyName = ((PropertyChangedEventArgs)args).PropertyName;
NestedPropertyInfo info;
if (this.nestedObjectInfos.TryGetValue(sender, out info))
if (this.nestedObjectInfos != null && this.nestedObjectInfos.TryGetValue(sender, out info))
{
this.NestedPropertyChanged(sender, info.rootItems, propertyName, info.nestedPropertyPath);
PropertyChangedEventArgs arguments = new PropertyChangedEventArgs(info.nestedPropertyPath + propertyName);
@ -136,7 +143,7 @@ namespace Telerik.Data.Core
}
else
{
if (this.nestedObjectInfos.Count > 0)
if (this.nestedObjectInfos != null && this.nestedObjectInfos.Count > 0)
{
this.NestedPropertyChanged(sender, new HashSet<object> { sender }, propertyName);
}
@ -147,7 +154,7 @@ namespace Telerik.Data.Core
}
}
void IDataSourceView.SubscribeToItemPropertyChanged()
void IDataSourceView.SubscribeToNestedItemPropertyChanged()
{
this.shouldSubsribeToPropertyChanged = true;
if (this.nestedObjectInfos == null)
@ -158,17 +165,14 @@ namespace Telerik.Data.Core
for (int i = 0; i < this.internalList.Count; i++)
{
object item = this.internalList[i];
this.RemovePropertyChangedHandler(item);
this.SubscribeToINotifyPropertyChanged(item, item, string.Empty);
}
}
void IDataSourceView.UnsubscribeFromItemPropertyChanged()
void IDataSourceView.UnsubscribeFromNestedItemPropertyChanged()
{
this.shouldSubsribeToPropertyChanged = false;
foreach (var item in this.internalList)
{
this.RemovePropertyChangedHandler(item);
}
if (this.nestedObjectInfos != null)
{
@ -370,16 +374,13 @@ namespace Telerik.Data.Core
{
this.internalList.Insert(newIndex, newItem);
if (this.shouldSubsribeToPropertyChanged)
if (this.shouldSubsribeToPropertyChanged && this.nestedObjectInfos != null && this.nestedObjectInfos.Count > 0)
{
if (this.nestedObjectInfos != null && this.nestedObjectInfos.Count > 0)
{
this.SubscribeToINotifyPropertyChanged(newItem, newItem, string.Empty);
}
else
{
this.AddPropertyChangedHandler(newItem);
}
this.SubscribeToINotifyPropertyChanged(newItem, newItem, string.Empty);
}
else
{
this.AddPropertyChangedHandler(newItem);
}
}
@ -414,7 +415,7 @@ namespace Telerik.Data.Core
this.supportsPropertyChangedInitialized = true;
}
if (this.itemSupportsPropertyChanged && this.shouldSubsribeToPropertyChanged)
if (this.itemSupportsPropertyChanged)
{
this.propertyChangedEventHandler.Subscribe(item);
}

Просмотреть файл

@ -23,7 +23,7 @@ namespace Telerik.Data.Core
void Dispose();
object GetGroupKey(object item, int level);
void SubscribeToItemPropertyChanged();
void UnsubscribeFromItemPropertyChanged();
void SubscribeToNestedItemPropertyChanged();
void UnsubscribeFromNestedItemPropertyChanged();
}
}

Просмотреть файл

@ -200,7 +200,6 @@ namespace Telerik.UI.Xaml.Controls.Data
}
this.localDataProvider.ItemsSource = this.itemsSource;
this.localDataProvider.DataView.SubscribeToItemPropertyChanged();
}
this.UpdateRequestedItems(null, false);

Просмотреть файл

@ -28,7 +28,7 @@ namespace Telerik.UI.Xaml.Controls.Grid.Model
private FilterDescriptorCollection filterDescriptors;
private AggregateDescriptorCollection aggregateDescriptors;
private bool isCurrentItemSynchronizing = false;
private bool enableLiveUpdates;
private bool listenForNestedPropertyChange;
public object ItemsSource
{
@ -122,16 +122,16 @@ namespace Telerik.UI.Xaml.Controls.Grid.Model
}
}
internal bool EnableLiveUpdates
internal bool ListenForNestedPropertyChange
{
get
{
return this.enableLiveUpdates;
return this.listenForNestedPropertyChange;
}
set
{
this.enableLiveUpdates = value;
this.UpdateDataViewPropertyChangeSubscription(this.enableLiveUpdates);
this.listenForNestedPropertyChange = value;
this.UpdateDataViewPropertyChangeSubscription(this.listenForNestedPropertyChange);
}
}
@ -140,7 +140,7 @@ namespace Telerik.UI.Xaml.Controls.Grid.Model
this.dataChangeFlags |= descriptor.UpdateFlags;
this.GridView.UpdateService.RegisterUpdate((int)UpdateFlags.AffectsData);
}
internal IEnumerable ForEachDataDescriptor()
{
foreach (var descriptor in this.filterDescriptors)
@ -218,7 +218,7 @@ namespace Telerik.UI.Xaml.Controls.Grid.Model
}
this.localDataProvider.ItemsSource = this.itemsSource;
this.UpdateDataViewPropertyChangeSubscription(this.enableLiveUpdates);
this.UpdateDataViewPropertyChangeSubscription(this.listenForNestedPropertyChange);
}
this.UpdateRequestedItems(null, false);
@ -324,7 +324,7 @@ namespace Telerik.UI.Xaml.Controls.Grid.Model
this.filterDescriptors.DescriptionCollection = provider.FilterDescriptions;
this.aggregateDescriptors.DescriptionCollection = provider.AggregateDescriptions;
}
private void CurrencyService_CurrentChanged(object sender, EventArgs e)
{
if (!this.isCurrentItemSynchronizing)
@ -468,7 +468,7 @@ namespace Telerik.UI.Xaml.Controls.Grid.Model
int groupDescriptionCount = this.CurrentDataProvider.Settings.RowGroupDescriptions.Count;
bool keepCollapsedState = (this.dataChangeFlags & DataChangeFlags.Group) == DataChangeFlags.None;
if (this.ShouldDisplayIncrementalLoadingIndicator)
{
this.rowLayout.LayoutStrategies.Add(new PlaceholderStrategy());
@ -645,11 +645,11 @@ namespace Telerik.UI.Xaml.Controls.Grid.Model
{
if (shouldSubscribe)
{
this.localDataProvider.DataView.SubscribeToItemPropertyChanged();
this.localDataProvider.DataView.SubscribeToNestedItemPropertyChanged();
}
else
{
this.localDataProvider.DataView.UnsubscribeFromItemPropertyChanged();
this.localDataProvider.DataView.UnsubscribeFromNestedItemPropertyChanged();
}
}
}

Просмотреть файл

@ -26,7 +26,6 @@ namespace Telerik.UI.Xaml.Controls.Grid.Model
{
this.executeOperationsSyncroniously = shouldExecuteSyncroniously;
this.TrackPropertyChanged = true;
this.EnableLiveUpdates = true;
this.GroupFactory = new DataGroupFactory();

Просмотреть файл

@ -131,10 +131,10 @@ namespace Telerik.UI.Xaml.Controls.Grid
DependencyProperty.Register(nameof(GroupPanelPosition), typeof(GroupPanelPosition), typeof(RadDataGrid), new PropertyMetadata(GroupPanelPosition.Left, OnGroupPanelPositionChanged));
/// <summary>
/// Identifies the <see cref="EnableLiveUpdates"/> dependency property.
/// Identifies the <see cref="ListenForNestedPropertyChange"/> dependency property.
/// </summary>
public static readonly DependencyProperty EnableLiveUpdatesProperty =
DependencyProperty.Register(nameof(EnableLiveUpdates), typeof(bool), typeof(RadDataGrid), new PropertyMetadata(true, OnEnableLiveUpdatesPropertyChanged));
public static readonly DependencyProperty ListenForNestedPropertyChangeProperty =
DependencyProperty.Register(nameof(ListenForNestedPropertyChange), typeof(bool), typeof(RadDataGrid), new PropertyMetadata(false, OnListenForNestedPropertyChangePropertyChanged));
private DataGridColumnHeaderPanel columnHeadersPanel;
private DataGridCellsPanel cellsPanel;
@ -583,15 +583,15 @@ namespace Telerik.UI.Xaml.Controls.Grid
/// <summary>
/// Gets or sets a value indicating whether the DataGrid should be updated if INotifyPropertyChanged item from its source is changed.
/// </summary>
public bool EnableLiveUpdates
public bool ListenForNestedPropertyChange
{
get
{
return (bool)this.GetValue(EnableLiveUpdatesProperty);
return (bool)this.GetValue(ListenForNestedPropertyChangeProperty);
}
set
{
this.SetValue(EnableLiveUpdatesProperty, value);
this.SetValue(ListenForNestedPropertyChangeProperty, value);
}
}
@ -1002,10 +1002,10 @@ namespace Telerik.UI.Xaml.Controls.Grid
}
}
private static void OnEnableLiveUpdatesPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
private static void OnListenForNestedPropertyChangePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
RadDataGrid grid = d as RadDataGrid;
grid.model.EnableLiveUpdates = (bool)e.NewValue;
grid.model.ListenForNestedPropertyChange = (bool)e.NewValue;
}
private static void OnColumnResizeModeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)

Просмотреть файл

@ -85,7 +85,7 @@ namespace SDKExamples.UWP.DataGrid
private void OnUpdateOnPropertyChangedButtonClicked(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
this.grid.EnableLiveUpdates = !this.grid.EnableLiveUpdates;
this.grid.ListenForNestedPropertyChange = !this.grid.ListenForNestedPropertyChange;
}
private void OnChangeFirstItemClicked(object sender, Windows.UI.Xaml.RoutedEventArgs e)