private static void OnFilterSourcePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { FeatureDataGrid grid = d as FeatureDataGrid; IEnumerable <Graphic> oldValue = e.OldValue as IEnumerable <Graphic>; IEnumerable <Graphic> newValue = e.NewValue as IEnumerable <Graphic>; if (oldValue != null && oldValue is ObservableCollection <Graphic> ) { (oldValue as ObservableCollection <Graphic>).CollectionChanged -= grid.FilterSource_CollectionChanged; } if (newValue != null && newValue is ObservableCollection <Graphic> ) { (newValue as ObservableCollection <Graphic>).CollectionChanged += grid.FilterSource_CollectionChanged; } if (grid.GraphicsLayer != null) { grid.SetItemsSource((grid.GraphicsLayer != null && grid.GraphicsLayer.Graphics != null) ? (IList <Graphic>)grid.GraphicsLayer.Graphics : new List <Graphic>()); } else { grid.ItemsSource = null; } grid.ResetLayout(); // Restoring previously selected graphics (if any): if (grid.GraphicsLayer != null) { grid.RestorePreviousSelection(grid.GraphicsLayer.SelectedGraphics); } }
private static void OnGraphicsLayerPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { FeatureDataGrid grid = d as FeatureDataGrid; GraphicsLayer oldValue = e.OldValue as GraphicsLayer; GraphicsLayer newValue = e.NewValue as GraphicsLayer; if (oldValue != null) { oldValue.PropertyChanged -= grid.GraphicsLayer_PropertyChanged; #region Mouse Hovering Support oldValue.MouseEnter -= grid.GraphicsLayer_MouseEnter; oldValue.MouseLeave -= grid.GraphicsLayer_MouseLeave; #endregion grid.UnregisterGraphicCollectionEventHandlers(); grid.currentGraphicCollection = null; // Setting the FeatureDataGrid's ItemsSource property to null: grid.ItemsSource = null; grid.ResetLayout(); } if (newValue != null) { #region Mouse Hovering Support newValue.MouseEnter += grid.GraphicsLayer_MouseEnter; newValue.MouseLeave += grid.GraphicsLayer_MouseLeave; #endregion if (!newValue.IsInitialized) { EventHandler <EventArgs> handler = null; handler = new EventHandler <EventArgs>( delegate(object s, EventArgs args) { grid.PopulateItemsSource(s as GraphicsLayer, handler); }); newValue.Initialized += handler; } else { grid.PopulateItemsSource(newValue, null); } } // Restoring previously selected graphics (if any): if (grid.GraphicsLayer != null) { grid.RestorePreviousSelection(grid.GraphicsLayer.SelectedGraphics); } }