protected override void OnVisualParentChanged(DependencyObject oldParent)
{
base.OnVisualParentChanged(oldParent);
// Windows OS bug:1988393; DevDiv bug:107459
// RibbonMenuItem, RibbonMenuButton, RibbonSplitButton and RibbonSplitMenuItem
// templates contains ItemsPresenter where Grid.IsSharedSizeScope="true" and
// need to inherits PrivateSharedSizeScopeProperty value. Property inheritance
// walks the locial tree if possible and skips the visual tree where the
// ItemsPresenter is. Workaround here is to copy the property value from the
// visual parent
DependencyObject newParent = VisualTreeHelper.GetParent(this);
// The Separtator is a logical child of a RibbonMenuItem, RibbonMenuButton,
// RibbonSplitButton or RibbonSplitMenuItem but has a different visual parent.
// Set one-way binding with visual parent for
// DefinitionBase.PrivateSharedSizeScopeProperty
if (newParent != null)
{
Binding binding = new Binding();
binding.Path = new PropertyPath(PrivateSharedSizeScopeProperty);
binding.Mode = BindingMode.OneWay;
binding.Source = newParent;
BindingOperations.SetBinding(this, PrivateSharedSizeScopeProperty, binding);
}
// Clear binding for DefinitionBase.PrivateSharedSizeScopeProperty as it
// is being detached from a visual parent.
if (newParent == null)
{
BindingOperations.ClearBinding(this, PrivateSharedSizeScopeProperty);
}
}