Skip to content

Commit 7ca15ae

Browse files
committed
Fixes #1185
1 parent 4df1343 commit 7ca15ae

File tree

3 files changed

+60
-31
lines changed

3 files changed

+60
-31
lines changed

Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- Simplified state was not updated when items changed
88
- [#1165](../../issues/1165) - ScreenTip is not DPI aware
99
- [#1183](../../issues/1183) - MenuItems, having a submenu, do not stay highlighted when MenuItem from the submenu is highlighted
10+
- [#1185](../../issues/1185) - LauncherIcon not rendered correctly and items in QAT can be removed from QAT in it's popup
1011
- [#1191](../../issues/1191) - Popup of DropDownButton/SplitButton has unwanted MinHeight
1112

1213
- ### Enhancements/Features

Fluent.Ribbon/Controls/Ribbon.cs

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ namespace Fluent;
2121
using Fluent.Helpers;
2222
using Fluent.Internal.KnownBoxes;
2323
using Fluent.Localization;
24-
using WindowChrome = ControlzEx.WindowChrome;
2524

2625
// TODO: improve style parts naming & using
2726

@@ -42,7 +41,7 @@ public class Ribbon : Control, ILogicalChildSupport
4241
/// <summary>
4342
/// Gets the current instance for storing the state of this control.
4443
/// </summary>
45-
public IRibbonStateStorage RibbonStateStorage => this.ribbonStateStorage ?? (this.ribbonStateStorage = this.CreateRibbonStateStorage());
44+
public IRibbonStateStorage RibbonStateStorage => this.ribbonStateStorage ??= this.CreateRibbonStateStorage();
4645

4746
/// <summary>
4847
/// Create a new instance for storing the state of this control.
@@ -446,38 +445,43 @@ private static void OnContextMenuOpened(object sender, RoutedEventArgs e)
446445
//Debug.WriteLine("Menu opened on "+control);
447446
if (control is not null)
448447
{
449-
FirstSeparator.Visibility = Visibility.Visible;
450-
451448
// Check for value because remove is only possible in the context menu of items in QA which represent the value for QA-items
452-
if (ribbon.QuickAccessElements.ContainsValue(control))
449+
if (ribbon.QuickAccessElements.ContainsValue(control)
450+
&& (control is not IDropDownControl dropDownControl || dropDownControl.IsDropDownOpen is false))
453451
{
452+
FirstSeparator.Visibility = Visibility.Visible;
453+
454454
// Control is on quick access
455455
RemoveFromQuickAccessMenuItem.Visibility = Visibility.Visible;
456456
}
457-
else if (control is System.Windows.Controls.MenuItem)
458-
{
459-
// Control is menu item
460-
AddMenuToQuickAccessMenuItem.Visibility = Visibility.Visible;
461-
}
462-
else if (control is Gallery ||
463-
control is InRibbonGallery)
464-
{
465-
// Control is gallery
466-
AddGalleryToQuickAccessMenuItem.Visibility = Visibility.Visible;
467-
}
468-
else if (control is RibbonGroupBox)
469-
{
470-
// Control is group box
471-
AddGroupToQuickAccessMenuItem.Visibility = Visibility.Visible;
472-
}
473-
else if (control is IQuickAccessItemProvider)
474-
{
475-
// Its other control
476-
AddToQuickAccessMenuItem.Visibility = Visibility.Visible;
477-
}
478457
else
479458
{
480-
FirstSeparator.Visibility = Visibility.Collapsed;
459+
FirstSeparator.Visibility = Visibility.Visible;
460+
461+
if (control is System.Windows.Controls.MenuItem)
462+
{
463+
// Control is menu item
464+
AddMenuToQuickAccessMenuItem.Visibility = Visibility.Visible;
465+
}
466+
else if (control is Gallery or InRibbonGallery)
467+
{
468+
// Control is gallery
469+
AddGalleryToQuickAccessMenuItem.Visibility = Visibility.Visible;
470+
}
471+
else if (control is RibbonGroupBox)
472+
{
473+
// Control is group box
474+
AddGroupToQuickAccessMenuItem.Visibility = Visibility.Visible;
475+
}
476+
else if (control is IQuickAccessItemProvider)
477+
{
478+
// Its other control
479+
AddToQuickAccessMenuItem.Visibility = Visibility.Visible;
480+
}
481+
else
482+
{
483+
FirstSeparator.Visibility = Visibility.Collapsed;
484+
}
481485
}
482486
}
483487
}
@@ -1507,16 +1511,17 @@ private static void OnAddToQuickAccessCommandCanExecute(object sender, CanExecut
15071511
{
15081512
if (sender is Ribbon ribbon
15091513
&& ribbon.IsQuickAccessToolBarVisible
1510-
&& QuickAccessItemsProvider.IsSupported(e.Parameter as UIElement)
1511-
&& ribbon.IsInQuickAccessToolBar(e.Parameter as UIElement) == false)
1514+
&& e.Parameter is UIElement element
1515+
&& QuickAccessItemsProvider.IsSupported(element)
1516+
&& ribbon.IsInQuickAccessToolBar(element) is false)
15121517
{
15131518
if (e.Parameter is Gallery gallery)
15141519
{
15151520
e.CanExecute = ribbon.IsInQuickAccessToolBar(FindParentRibbonControl(gallery) as UIElement) == false;
15161521
}
15171522
else
15181523
{
1519-
e.CanExecute = ribbon.IsInQuickAccessToolBar(e.Parameter as UIElement) == false;
1524+
e.CanExecute = ribbon.IsInQuickAccessToolBar(element) == false;
15201525
}
15211526
}
15221527
else

Fluent.Ribbon/Controls/RibbonGroupBox.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,12 @@ private void OnUnloaded(object sender, RoutedEventArgs e)
749749
{
750750
this.SetCurrentValue(IsDropDownOpenProperty, false);
751751

752+
if (this.IsDropDownOpen
753+
&& this.State is RibbonGroupBoxState.QuickAccess)
754+
{
755+
this.OnPopupClosed(this, EventArgs.Empty);
756+
}
757+
752758
this.UnSubscribeEvents();
753759
}
754760

@@ -1187,7 +1193,6 @@ public virtual FrameworkElement CreateQuickAccessItem()
11871193
RibbonControl.Bind(this, groupBox, nameof(this.LauncherCommandParameter), LauncherCommandParameterProperty, BindingMode.OneWay);
11881194
RibbonControl.Bind(this, groupBox, nameof(this.LauncherCommand), LauncherCommandProperty, BindingMode.OneWay);
11891195
RibbonControl.Bind(this, groupBox, nameof(this.LauncherCommandTarget), LauncherCommandTargetProperty, BindingMode.OneWay);
1190-
RibbonControl.Bind(this, groupBox, nameof(this.LauncherIcon), LauncherIconProperty, BindingMode.OneWay);
11911196
RibbonControl.Bind(this, groupBox, nameof(this.LauncherText), LauncherTextProperty, BindingMode.OneWay);
11921197
RibbonControl.Bind(this, groupBox, nameof(this.LauncherToolTip), LauncherToolTipProperty, BindingMode.OneWay);
11931198
RibbonControl.Bind(this, groupBox, nameof(this.IsLauncherEnabled), IsLauncherEnabledProperty, BindingMode.OneWay);
@@ -1213,6 +1218,24 @@ public virtual FrameworkElement CreateQuickAccessItem()
12131218
}
12141219
}
12151220

1221+
if (this.LauncherIcon is not null)
1222+
{
1223+
if (this.LauncherIcon is Visual iconVisual)
1224+
{
1225+
var rect = new Rectangle
1226+
{
1227+
Width = 16,
1228+
Height = 16,
1229+
Fill = new VisualBrush(iconVisual)
1230+
};
1231+
groupBox.LauncherIcon = rect;
1232+
}
1233+
else
1234+
{
1235+
RibbonControl.Bind(this, groupBox, nameof(this.LauncherIcon), RibbonGroupBox.LauncherIconProperty, BindingMode.OneWay);
1236+
}
1237+
}
1238+
12161239
return groupBox;
12171240
}
12181241

0 commit comments

Comments
 (0)