From 48d9d19df141e85a5a9a7689fdacafefe06f99d1 Mon Sep 17 00:00:00 2001 From: Michael Jolley Date: Wed, 28 May 2025 14:35:26 -0500 Subject: [PATCH] CmdPal: Styling critical context items using the SystemFillColorCriticalBrush (#39645) Styles context items based on the IsCritical property. ![image](https://github.com/user-attachments/assets/aa1ee0b0-de09-45af-8f5e-74dff666fbb4) ![image](https://github.com/user-attachments/assets/90a7f750-c949-4f76-b699-db2e29251414) Closes #38307 --- .../cmdpal/Microsoft.CmdPal.UI/App.xaml | 1 + .../Controls/CommandBar.xaml | 43 +++++++++++++++++-- .../Converters/ContextItemTemplateSelector.cs | 21 +++++++++ .../Microsoft.CmdPal.UI.csproj | 4 +- .../Microsoft.CmdPal.UI/Styles/TextBlock.xaml | 27 ++++++++++++ .../Components/ContextMenuHelper.cs | 1 + 6 files changed, 91 insertions(+), 6 deletions(-) create mode 100644 src/modules/cmdpal/Microsoft.CmdPal.UI/Converters/ContextItemTemplateSelector.cs create mode 100644 src/modules/cmdpal/Microsoft.CmdPal.UI/Styles/TextBlock.xaml diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/App.xaml b/src/modules/cmdpal/Microsoft.CmdPal.UI/App.xaml index ffcca6b3a8..9f4adee20a 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI/App.xaml +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/App.xaml @@ -11,6 +11,7 @@ + diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/CommandBar.xaml b/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/CommandBar.xaml index 203009f763..d4c4f49879 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/CommandBar.xaml +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/CommandBar.xaml @@ -34,8 +34,13 @@ Orientation="Vertical" Spacing="4" /> - - + + + + @@ -63,6 +68,38 @@ Text="{x:Bind RequestedShortcut, Mode=OneWay, Converter={StaticResource KeyChordToStringConverter}}" /> + + + + + + + + + + + + + + + @@ -237,7 +274,7 @@ Margin="-16,-12,-16,-12" IsItemClickEnabled="True" ItemClick="CommandsDropdown_ItemClick" - ItemTemplate="{StaticResource ContextMenuViewModelTemplate}" + ItemTemplateSelector="{StaticResource ContextItemTemplateSelector}" ItemsSource="{x:Bind ViewModel.ContextMenu.FilteredItems, Mode=OneWay}" KeyDown="CommandsDropdown_KeyDown" SelectionMode="Single"> diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/Converters/ContextItemTemplateSelector.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI/Converters/ContextItemTemplateSelector.cs new file mode 100644 index 0000000000..b9ff7c3439 --- /dev/null +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/Converters/ContextItemTemplateSelector.cs @@ -0,0 +1,21 @@ +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using Microsoft.CmdPal.UI.ViewModels; +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Controls; + +namespace Microsoft.CmdPal.UI; + +internal sealed partial class ContextItemTemplateSelector : DataTemplateSelector +{ + public DataTemplate? Default { get; set; } + + public DataTemplate? Critical { get; set; } + + protected override DataTemplate? SelectTemplateCore(object item) + { + return ((CommandContextItemViewModel)item).IsCritical ? Critical : Default; + } +} diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/Microsoft.CmdPal.UI.csproj b/src/modules/cmdpal/Microsoft.CmdPal.UI/Microsoft.CmdPal.UI.csproj index b3ec6188cf..0b653d2d0a 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI/Microsoft.CmdPal.UI.csproj +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/Microsoft.CmdPal.UI.csproj @@ -39,9 +39,7 @@ - + diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/Styles/TextBlock.xaml b/src/modules/cmdpal/Microsoft.CmdPal.UI/Styles/TextBlock.xaml new file mode 100644 index 0000000000..6160585127 --- /dev/null +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/Styles/TextBlock.xaml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Components/ContextMenuHelper.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Components/ContextMenuHelper.cs index cbadadc699..a2064b0369 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Components/ContextMenuHelper.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WindowWalker/Components/ContextMenuHelper.cs @@ -36,6 +36,7 @@ internal sealed class ContextMenuHelper contextMenu.Add(new CommandContextItem(new KillProcessCommand(windowData)) { RequestedShortcut = KeyChordHelpers.FromModifiers(true, false, false, false, (int)VirtualKey.Delete, 0), + IsCritical = true, }); }