diff --git a/Fluent.Ribbon/Controls/Backstage.cs b/Fluent.Ribbon/Controls/Backstage.cs index 884f2bec7..77241b86e 100644 --- a/Fluent.Ribbon/Controls/Backstage.cs +++ b/Fluent.Ribbon/Controls/Backstage.cs @@ -164,21 +164,7 @@ public UIElement Content /// This enables animation, styling, binding, etc... /// public static readonly DependencyProperty ContentProperty = - DependencyProperty.Register(nameof(Content), typeof(UIElement), typeof(Backstage), new UIPropertyMetadata(null, OnContentChanged)); - - private static void OnContentChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) - { - var backstage = (Backstage)d; - if (e.OldValue != null) - { - backstage.RemoveLogicalChild(e.OldValue); - } - - if (e.NewValue != null) - { - backstage.AddLogicalChild(e.NewValue); - } - } + DependencyProperty.Register(nameof(Content), typeof(UIElement), typeof(Backstage), new UIPropertyMetadata(null)); #endregion diff --git a/Fluent.Ribbon/Controls/DropDownButton.cs b/Fluent.Ribbon/Controls/DropDownButton.cs index 9285ddf22..f0884e35f 100644 --- a/Fluent.Ribbon/Controls/DropDownButton.cs +++ b/Fluent.Ribbon/Controls/DropDownButton.cs @@ -152,27 +152,7 @@ public object Icon /// /// Using a DependencyProperty as the backing store for Icon. This enables animation, styling, binding, etc... /// - public static readonly DependencyProperty IconProperty = RibbonControl.IconProperty.AddOwner(typeof(DropDownButton), new UIPropertyMetadata(null, OnIconChanged)); - - private static void OnIconChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) - { - var element = (DropDownButton)d; - - var oldElement = e.OldValue as FrameworkElement; - - if (oldElement != null) - { - element.RemoveLogicalChild(oldElement); - } - - var newElement = e.NewValue as FrameworkElement; - - if (newElement != null - && LogicalTreeHelper.GetParent(newElement) == null) - { - element.AddLogicalChild(newElement); - } - } + public static readonly DependencyProperty IconProperty = RibbonControl.IconProperty.AddOwner(typeof(DropDownButton), new UIPropertyMetadata(null)); #endregion @@ -732,7 +712,7 @@ private static void OnIsDropDownOpenChanged(DependencyObject d, DependencyProper control.Dispatcher.BeginInvoke( DispatcherPriority.Normal, - (DispatcherOperationCallback)delegate(object arg) + (DispatcherOperationCallback)delegate (object arg) { var ctrl = (DropDownButton)arg; @@ -798,9 +778,9 @@ private void OnDropDownOpened() public virtual FrameworkElement CreateQuickAccessItem() { var button = new DropDownButton - { - Size = RibbonControlSize.Small - }; + { + Size = RibbonControlSize.Small + }; this.BindQuickAccessItem(button); RibbonControl.Bind(this, button, "DisplayMemberPath", DisplayMemberPathProperty, BindingMode.OneWay); @@ -825,7 +805,7 @@ public virtual FrameworkElement CreateQuickAccessItem() /// protected void OnQuickAccessOpened(object sender, EventArgs e) { - var buttonInQuickAccess = (DropDownButton)sender; + var buttonInQuickAccess = (DropDownButton)sender; buttonInQuickAccess.DropDownClosed += this.OnQuickAccessMenuClosedOrUnloaded; buttonInQuickAccess.Unloaded += this.OnQuickAccessMenuClosedOrUnloaded; @@ -902,6 +882,11 @@ protected override IEnumerator LogicalChildren yield return this.Icon; } + if (this.LargeIcon != null) + { + yield return this.LargeIcon; + } + foreach (var item in this.Items) { yield return item; diff --git a/Fluent.Ribbon/Controls/Ribbon.cs b/Fluent.Ribbon/Controls/Ribbon.cs index 0ea5718de..ce05a67a7 100644 --- a/Fluent.Ribbon/Controls/Ribbon.cs +++ b/Fluent.Ribbon/Controls/Ribbon.cs @@ -444,7 +444,7 @@ public UIElement Menu /// This enables animation, styling, binding, etc... /// public static readonly DependencyProperty MenuProperty = - DependencyProperty.Register(nameof(Menu), typeof(UIElement), typeof(Ribbon), new UIPropertyMetadata(null, AddOrRemoveLogicalChildOnPropertyChanged)); + DependencyProperty.Register(nameof(Menu), typeof(UIElement), typeof(Ribbon), new UIPropertyMetadata(null)); #endregion @@ -461,7 +461,7 @@ public StartScreen StartScreen /// for /// public static readonly DependencyProperty StartScreenProperty = - DependencyProperty.Register(nameof(StartScreen), typeof(StartScreen), typeof(Ribbon), new UIPropertyMetadata(null, AddOrRemoveLogicalChildOnPropertyChanged)); + DependencyProperty.Register(nameof(StartScreen), typeof(StartScreen), typeof(Ribbon), new UIPropertyMetadata(null)); /// /// Window title @@ -557,20 +557,6 @@ private static void OnSelectedTabIndexChanged(DependencyObject d, DependencyProp } } - private static void AddOrRemoveLogicalChildOnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) - { - var ribbon = (Ribbon)d; - if (e.OldValue != null) - { - ribbon.RemoveLogicalChild(e.OldValue); - } - - if (e.NewValue != null) - { - ribbon.AddLogicalChild(e.NewValue); - } - } - /// /// Gets the first visible TabItem /// @@ -849,8 +835,7 @@ protected override IEnumerator LogicalChildren yield return this.QuickAccessToolBar; } - if (this.TabControl != null - && this.TabControl.ToolbarPanel != null) + if (this.TabControl?.ToolbarPanel != null) { yield return this.TabControl.ToolbarPanel; } @@ -1455,18 +1440,8 @@ protected override void OnGotFocus(RoutedEventArgs e) [SuppressMessage("Microsoft.Maintainability", "CA1502")] public override void OnApplyTemplate() { - if (this.layoutRoot != null) - { - this.RemoveLogicalChild(this.layoutRoot); - } - this.layoutRoot = this.GetTemplateChild("PART_LayoutRoot") as Panel; - if (this.layoutRoot != null) - { - this.AddLogicalChild(this.layoutRoot); - } - if (this.TitleBar != null) { foreach (var ribbonContextualTabGroup in this.ContextualGroups) @@ -1573,11 +1548,6 @@ public override void OnApplyTemplate() }; this.QuickAccessToolBar.SetBinding(QuickAccessToolBar.CanQuickAccessLocationChangingProperty, binding); - if (this.QuickAccessToolBar.Parent == null) - { - this.AddLogicalChild(this.QuickAccessToolBar); - } - this.QuickAccessToolBar.Loaded += this.OnFirstToolbarLoaded; } }