/// <summary> /// Delayed loading of the property inspector to avoid creating the entire list of property /// editors immediately after selection. Keeps that app running smooth. /// </summary> /// <param name="performInitialization"></param> /// <returns></returns> void ProcessIncrementalPropertyAdd() { var numberToAdd = 10; if (propertiesToAdd == null) { propertiesToAdd = PropertyInformation.GetProperties(target).GetEnumerator(); numberToAdd = 0; } var i = 0; for (; i < numberToAdd && propertiesToAdd.MoveNext(); ++i) { // iterate over the PropertyInfo objects, // setting the property grid's filter on each object, // and adding those properties to the observable collection of propertiesToSort (this.properties) var property = propertiesToAdd.Current; property.Filter = Filter; if (property.IsVisible) { Properties.Add(property); } allProperties.Add(property); // checking whether a property is visible ... actually runs the property filtering code if (property.IsVisible) { property.Index = visiblePropertyCount++; } } if (i == numberToAdd) { processIncrementalCall.Enqueue(); } else { propertiesToAdd = null; } }
public PropertyGrid2() { processRefreshCall = new DelayedCall(ProcessRefresh, DispatcherPriority.ApplicationIdle); processIncrementalCall = new DelayedCall(ProcessIncrementalPropertyAdd, DispatcherPriority.Background); filterCall = new DelayedCall(ProcessFilter, DispatcherPriority.Background); InitializeComponent(); Loaded += HandleLoaded; Unloaded += HandleUnloaded; CommandBindings.Add(new CommandBinding(ShowBindingErrorsCommand, HandleShowBindingErrors, CanShowBindingErrors)); CommandBindings.Add(new CommandBinding(ClearCommand, HandleClear, CanClear)); CommandBindings.Add(new CommandBinding(SortCommand, HandleSort)); filterTimer = new DispatcherTimer(); filterTimer.Interval = TimeSpan.FromSeconds(0.3); filterTimer.Tick += (s, e) => { filterCall.Enqueue(); filterTimer.Stop(); }; }
void EnqueueAfterSettingFilter() { filterCall.Enqueue(); }