/// <summary> /// Initializes the <see cref="ItemsControl.ItemsSource"/> property with the <see cref="SubItemsProvider"/>. /// </summary> /// <returns><c>true</c>, if the <see cref="ItemsControl.ItemsSource"/> property was changed by this method, else <c>false</c>.</returns> protected virtual bool InitializeSubItemsSource() { SubItemsProvider sip = SubItemsProvider; IEnumerable oldItemsSource = ItemsSource; if (!_contextChangedAttached) { ContextChanged += OnContextChanged; _contextChangedAttached = true; } if (_attachedContextSource != null) { _attachedContextSource.Detach(OnDataContextValueChanged); } _attachedContextSource = DataContext.EvaluatedSourceValue; _attachedContextSource.Attach(OnDataContextValueChanged); object context = Context; if (context == null) { return(false); } ItemsSource = sip == null ? null : sip.GetSubItems(context); if (oldItemsSource == ItemsSource) { return(false); } MPF.TryCleanupAndDispose(oldItemsSource); CheckExpandable(); return(true); }
protected override void PrepareItemsOverride(bool force) { SubItemsProvider sip = SubItemsProvider; if (sip == null) { return; } if (ItemsSource == null) { if (InitializeSubItemsSource()) // This could trigger a recursive call of PrepareItems(true) if the ItemsSource was changed, that's why we set _preventItemsPreparation above { force = true; } } base.PrepareItemsOverride(force); }