private SetItemsSource ( IEnumerable |
||
graphics | IEnumerable |
The graphics. |
Résultat | void |
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) { if (grid.featureLayer != null) { grid.featureLayer.UpdateCompleted -= grid.FeatureLayer_UpdateCompleted; grid.featureLayer = null; // clear out reference to old feature layer if it exists } oldValue.PropertyChanged -= grid.GraphicsLayer_PropertyChanged; BindingOperations.ClearBinding(grid, FeatureDataGrid.TotalGraphicCountProperty); BindingOperations.ClearBinding(grid, FeatureDataGrid.SelectedGraphicCountProperty); if (!oldValue.IsInitialized) { oldValue.Initialized -= grid.GraphicsLayer_Initialized; } } if (newValue != null) { // if new layer is feature layer set private member if (newValue is FeatureLayer) { grid.featureLayer = newValue as FeatureLayer; grid.OutFields = grid.featureLayer.OutFields.ToString(); grid.featureLayer.UpdateCompleted += grid.FeatureLayer_UpdateCompleted; } else { grid.GraphicCollection = newValue.Graphics; } if (newValue.IsInitialized) { newValue.PropertyChanged += grid.GraphicsLayer_PropertyChanged; grid.SetItemsSource(newValue.Graphics); // Set the ItemsSource grid.BindToTotalGraphicsCount(); // Add total graphic count binding. grid.BindToSelectedGraphicsCount(); // Add selected graphic count binding. } else { // Wait for initialize event to fire before configuring feature data grid newValue.Initialized += grid.GraphicsLayer_Initialized; } } grid.UpdateRecordsText(); // Update the status bar text. grid.SetSubmitButtonVisibility(); // Enable/Disable submit button option. grid.SetDeleteSelectedRowsMenuButtonEnableState(); // Enable/Disable delete option. }