private static void OnIconChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { RibbonControl element = d as RibbonControl; FrameworkElement oldElement = e.OldValue as FrameworkElement; if (oldElement != null) { element.RemoveLogicalChild(oldElement); } FrameworkElement newElement = e.NewValue as FrameworkElement; if (newElement != null) { element.AddLogicalChild(newElement); } }