private static void OnHasItemsPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
TreeViewItem source = d as TreeViewItem;
// Ignore the change if requested
if (source.IgnorePropertyChange)
{
source.IgnorePropertyChange = false;
return;
}
// Ensure the property is only written when expected
if (!source._allowWrite)
{
// Reset the old value before it was incorrectly written
source.IgnorePropertyChange = true;
source.SetValue(HasItemsProperty, e.OldValue);
throw new InvalidOperationException();
}
source.UpdateVisualState(true);
}