diff --git a/.github/actions/spell-check/expect.txt b/.github/actions/spell-check/expect.txt
index 8ae7b6efff..4a208a400a 100644
--- a/.github/actions/spell-check/expect.txt
+++ b/.github/actions/spell-check/expect.txt
@@ -1497,6 +1497,7 @@ psz
ptb
ptc
PTCHAR
+ptcontrols
ptd
PTOKEN
PToy
diff --git a/PowerToys.slnx b/PowerToys.slnx
index 4382ca5934..fabd54f0f0 100644
--- a/PowerToys.slnx
+++ b/PowerToys.slnx
@@ -13,6 +13,10 @@
+
+
+
+
diff --git a/src/common/Common.UI.Controls/Common.UI.Controls.csproj b/src/common/Common.UI.Controls/Common.UI.Controls.csproj
new file mode 100644
index 0000000000..9f2f1b490c
--- /dev/null
+++ b/src/common/Common.UI.Controls/Common.UI.Controls.csproj
@@ -0,0 +1,30 @@
+
+
+
+
+
+ Library
+ net9.0-windows10.0.26100.0
+ Microsoft.PowerToys.Common.UI.Controls
+ PowerToys.Common.UI.Controls
+ true
+ true
+ true
+ PowerToys.Common.UI.Controls.pri
+ enable
+ x64;ARM64
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/settings-ui/Settings.UI/SettingsXAML/Controls/CheckBoxWithDescriptionControl.cs b/src/common/Common.UI.Controls/Controls/CheckBoxWithDescriptionControl/CheckBoxWithDescriptionControl.cs
similarity index 89%
rename from src/settings-ui/Settings.UI/SettingsXAML/Controls/CheckBoxWithDescriptionControl.cs
rename to src/common/Common.UI.Controls/Controls/CheckBoxWithDescriptionControl/CheckBoxWithDescriptionControl.cs
index 854bf8cd72..3157515b0a 100644
--- a/src/settings-ui/Settings.UI/SettingsXAML/Controls/CheckBoxWithDescriptionControl.cs
+++ b/src/common/Common.UI.Controls/Controls/CheckBoxWithDescriptionControl/CheckBoxWithDescriptionControl.cs
@@ -1,4 +1,4 @@
-// Copyright (c) Microsoft Corporation
+// 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.
@@ -8,7 +8,7 @@ using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Automation;
using Microsoft.UI.Xaml.Controls;
-namespace Microsoft.PowerToys.Settings.UI.Controls
+namespace Microsoft.PowerToys.Common.UI.Controls
{
public partial class CheckBoxWithDescriptionControl : CheckBox
{
@@ -39,7 +39,7 @@ namespace Microsoft.PowerToys.Settings.UI.Controls
// Add text box only if the description is not empty. Required for additional plugin options.
if (!string.IsNullOrWhiteSpace(Description))
{
- panel.Children.Add(new IsEnabledTextBlock() { Style = (Style)App.Current.Resources["SecondaryIsEnabledTextBlockStyle"], Text = Description });
+ panel.Children.Add(new IsEnabledTextBlock() { Style = (Style)Application.Current.Resources["SecondaryIsEnabledTextBlockStyle"], Text = Description });
}
this.Content = panel;
diff --git a/src/settings-ui/Settings.UI/SettingsXAML/Controls/IsEnabledTextBlock.xaml b/src/common/Common.UI.Controls/Controls/IsEnabledTextBlock/IsEnabledTextBlock.xaml
similarity index 92%
rename from src/settings-ui/Settings.UI/SettingsXAML/Controls/IsEnabledTextBlock.xaml
rename to src/common/Common.UI.Controls/Controls/IsEnabledTextBlock/IsEnabledTextBlock.xaml
index a1f446917b..2ecd30ee4b 100644
--- a/src/settings-ui/Settings.UI/SettingsXAML/Controls/IsEnabledTextBlock.xaml
+++ b/src/common/Common.UI.Controls/Controls/IsEnabledTextBlock/IsEnabledTextBlock.xaml
@@ -1,7 +1,7 @@
-
+ xmlns:controls="using:Microsoft.PowerToys.Common.UI.Controls">
@@ -36,11 +36,13 @@
+
+
diff --git a/src/settings-ui/Settings.UI/SettingsXAML/Controls/IsEnabledTextBlock.xaml.cs b/src/common/Common.UI.Controls/Controls/IsEnabledTextBlock/IsEnabledTextBlock.xaml.cs
similarity index 92%
rename from src/settings-ui/Settings.UI/SettingsXAML/Controls/IsEnabledTextBlock.xaml.cs
rename to src/common/Common.UI.Controls/Controls/IsEnabledTextBlock/IsEnabledTextBlock.xaml.cs
index e7f8a52f25..7c1d64f0f9 100644
--- a/src/settings-ui/Settings.UI/SettingsXAML/Controls/IsEnabledTextBlock.xaml.cs
+++ b/src/common/Common.UI.Controls/Controls/IsEnabledTextBlock/IsEnabledTextBlock.xaml.cs
@@ -1,4 +1,4 @@
-// Copyright (c) Microsoft Corporation
+// 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.
@@ -7,7 +7,7 @@ using System.ComponentModel;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
-namespace Microsoft.PowerToys.Settings.UI.Controls
+namespace Microsoft.PowerToys.Common.UI.Controls
{
[TemplateVisualState(Name = "Normal", GroupName = "CommonStates")]
[TemplateVisualState(Name = "Disabled", GroupName = "CommonStates")]
@@ -15,7 +15,7 @@ namespace Microsoft.PowerToys.Settings.UI.Controls
{
public IsEnabledTextBlock()
{
- this.DefaultStyleKey = typeof(KeyVisual);
+ this.DefaultStyleKey = typeof(IsEnabledTextBlock);
}
protected override void OnApplyTemplate()
diff --git a/src/settings-ui/Settings.UI/SettingsXAML/Controls/KeyVisual/KeyCharPresenter.xaml b/src/common/Common.UI.Controls/Controls/KeyVisual/KeyCharPresenter.xaml
similarity index 99%
rename from src/settings-ui/Settings.UI/SettingsXAML/Controls/KeyVisual/KeyCharPresenter.xaml
rename to src/common/Common.UI.Controls/Controls/KeyVisual/KeyCharPresenter.xaml
index a28874b4ee..a162a67110 100644
--- a/src/settings-ui/Settings.UI/SettingsXAML/Controls/KeyVisual/KeyCharPresenter.xaml
+++ b/src/common/Common.UI.Controls/Controls/KeyVisual/KeyCharPresenter.xaml
@@ -2,7 +2,7 @@
diff --git a/src/settings-ui/Settings.UI/SettingsXAML/Controls/KeyVisual/KeyCharPresenter.xaml.cs b/src/common/Common.UI.Controls/Controls/KeyVisual/KeyCharPresenter.xaml.cs
similarity index 70%
rename from src/settings-ui/Settings.UI/SettingsXAML/Controls/KeyVisual/KeyCharPresenter.xaml.cs
rename to src/common/Common.UI.Controls/Controls/KeyVisual/KeyCharPresenter.xaml.cs
index 43ba496712..ce531c8dc5 100644
--- a/src/settings-ui/Settings.UI/SettingsXAML/Controls/KeyVisual/KeyCharPresenter.xaml.cs
+++ b/src/common/Common.UI.Controls/Controls/KeyVisual/KeyCharPresenter.xaml.cs
@@ -2,18 +2,10 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Runtime.InteropServices.WindowsRuntime;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
-using Microsoft.UI.Xaml.Data;
-using Microsoft.UI.Xaml.Documents;
-using Microsoft.UI.Xaml.Input;
-using Microsoft.UI.Xaml.Media;
-namespace Microsoft.PowerToys.Settings.UI.Controls;
+namespace Microsoft.PowerToys.Common.UI.Controls;
public sealed partial class KeyCharPresenter : Control
{
diff --git a/src/settings-ui/Settings.UI/SettingsXAML/Controls/KeyVisual/KeyVisual.xaml b/src/common/Common.UI.Controls/Controls/KeyVisual/KeyVisual.xaml
similarity index 99%
rename from src/settings-ui/Settings.UI/SettingsXAML/Controls/KeyVisual/KeyVisual.xaml
rename to src/common/Common.UI.Controls/Controls/KeyVisual/KeyVisual.xaml
index 9c820ba12c..147c7d782a 100644
--- a/src/settings-ui/Settings.UI/SettingsXAML/Controls/KeyVisual/KeyVisual.xaml
+++ b/src/common/Common.UI.Controls/Controls/KeyVisual/KeyVisual.xaml
@@ -1,7 +1,7 @@
-
+ xmlns:local="using:Microsoft.PowerToys.Common.UI.Controls">
@@ -210,4 +210,4 @@
-
\ No newline at end of file
+
diff --git a/src/settings-ui/Settings.UI/SettingsXAML/Controls/KeyVisual/KeyVisual.xaml.cs b/src/common/Common.UI.Controls/Controls/KeyVisual/KeyVisual.xaml.cs
similarity index 97%
rename from src/settings-ui/Settings.UI/SettingsXAML/Controls/KeyVisual/KeyVisual.xaml.cs
rename to src/common/Common.UI.Controls/Controls/KeyVisual/KeyVisual.xaml.cs
index 87dc9a4c21..1439a6e1d9 100644
--- a/src/settings-ui/Settings.UI/SettingsXAML/Controls/KeyVisual/KeyVisual.xaml.cs
+++ b/src/common/Common.UI.Controls/Controls/KeyVisual/KeyVisual.xaml.cs
@@ -1,4 +1,4 @@
-// Copyright (c) Microsoft Corporation
+// 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.
@@ -6,7 +6,7 @@ using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Windows.System;
-namespace Microsoft.PowerToys.Settings.UI.Controls
+namespace Microsoft.PowerToys.Common.UI.Controls
{
[TemplatePart(Name = KeyPresenter, Type = typeof(KeyCharPresenter))]
[TemplateVisualState(Name = NormalState, GroupName = "CommonStates")]
@@ -20,7 +20,7 @@ namespace Microsoft.PowerToys.Settings.UI.Controls
private const string DisabledState = "Disabled";
private const string InvalidState = "Invalid";
private const string WarningState = "Warning";
- private KeyCharPresenter _keyPresenter;
+ private KeyCharPresenter _keyPresenter = null!;
public object Content
{
diff --git a/src/settings-ui/Settings.UI/SettingsXAML/Controls/ShortcutControl/ShortcutWithTextLabelControl.xaml b/src/common/Common.UI.Controls/Controls/ShortcutWithTextLabelControl/ShortcutWithTextLabelControl.xaml
similarity index 98%
rename from src/settings-ui/Settings.UI/SettingsXAML/Controls/ShortcutControl/ShortcutWithTextLabelControl.xaml
rename to src/common/Common.UI.Controls/Controls/ShortcutWithTextLabelControl/ShortcutWithTextLabelControl.xaml
index 719091a787..c846010509 100644
--- a/src/settings-ui/Settings.UI/SettingsXAML/Controls/ShortcutControl/ShortcutWithTextLabelControl.xaml
+++ b/src/common/Common.UI.Controls/Controls/ShortcutWithTextLabelControl/ShortcutWithTextLabelControl.xaml
@@ -2,7 +2,7 @@
diff --git a/src/settings-ui/Settings.UI/SettingsXAML/Controls/ShortcutControl/ShortcutWithTextLabelControl.xaml.cs b/src/common/Common.UI.Controls/Controls/ShortcutWithTextLabelControl/ShortcutWithTextLabelControl.xaml.cs
similarity index 98%
rename from src/settings-ui/Settings.UI/SettingsXAML/Controls/ShortcutControl/ShortcutWithTextLabelControl.xaml.cs
rename to src/common/Common.UI.Controls/Controls/ShortcutWithTextLabelControl/ShortcutWithTextLabelControl.xaml.cs
index 7e4d31c28b..1a2913d254 100644
--- a/src/settings-ui/Settings.UI/SettingsXAML/Controls/ShortcutControl/ShortcutWithTextLabelControl.xaml.cs
+++ b/src/common/Common.UI.Controls/Controls/ShortcutWithTextLabelControl/ShortcutWithTextLabelControl.xaml.cs
@@ -7,7 +7,7 @@ using CommunityToolkit.WinUI.Controls;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
-namespace Microsoft.PowerToys.Settings.UI.Controls
+namespace Microsoft.PowerToys.Common.UI.Controls
{
public sealed partial class ShortcutWithTextLabelControl : Control
{
diff --git a/src/settings-ui/Settings.UI/Converters/BoolToKeyVisualStateConverter.cs b/src/common/Common.UI.Controls/Converters/BoolToKeyVisualStateConverter.cs
similarity index 81%
rename from src/settings-ui/Settings.UI/Converters/BoolToKeyVisualStateConverter.cs
rename to src/common/Common.UI.Controls/Converters/BoolToKeyVisualStateConverter.cs
index 04a62b02c7..47c9305cb3 100644
--- a/src/settings-ui/Settings.UI/Converters/BoolToKeyVisualStateConverter.cs
+++ b/src/common/Common.UI.Controls/Converters/BoolToKeyVisualStateConverter.cs
@@ -1,16 +1,11 @@
-// Copyright (c) Microsoft Corporation
+// 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 System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using Microsoft.PowerToys.Settings.UI.Controls;
using Microsoft.UI.Xaml.Data;
-namespace Microsoft.PowerToys.Settings.UI.Converters
+namespace Microsoft.PowerToys.Common.UI.Controls
{
public partial class BoolToKeyVisualStateConverter : IValueConverter
{
diff --git a/src/common/Common.UI.Controls/Themes/Generic.xaml b/src/common/Common.UI.Controls/Themes/Generic.xaml
new file mode 100644
index 0000000000..201150458c
--- /dev/null
+++ b/src/common/Common.UI.Controls/Themes/Generic.xaml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
diff --git a/src/modules/cmdpal/CommandPalette.slnf b/src/modules/cmdpal/CommandPalette.slnf
index c6ccbb7338..decc56060f 100644
--- a/src/modules/cmdpal/CommandPalette.slnf
+++ b/src/modules/cmdpal/CommandPalette.slnf
@@ -3,6 +3,7 @@
"path": "..\\..\\..\\PowerToys.slnx",
"projects": [
"src\\common\\CalculatorEngineCommon\\CalculatorEngineCommon.vcxproj",
+ "src\\common\\Common.UI.Controls\\Common.UI.Controls.csproj",
"src\\common\\ManagedCommon\\ManagedCommon.csproj",
"src\\common\\ManagedCsWin32\\ManagedCsWin32.csproj",
"src\\common\\ManagedTelemetry\\Telemetry\\ManagedTelemetry.csproj",
diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/App.xaml b/src/modules/cmdpal/Microsoft.CmdPal.UI/App.xaml
index d8d4655291..efddeddb84 100644
--- a/src/modules/cmdpal/Microsoft.CmdPal.UI/App.xaml
+++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/App.xaml
@@ -5,6 +5,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="using:Microsoft.CmdPal.UI.Controls"
xmlns:local="using:Microsoft.CmdPal.UI"
+ xmlns:ptcontrols="using:Microsoft.PowerToys.Common.UI.Controls"
xmlns:services="using:Microsoft.CmdPal.UI.Services">
@@ -16,8 +17,10 @@
-
-
+
+
+
+
@@ -25,7 +28,7 @@
240
-
+
diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/CheckBoxWithDescriptionControl.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/CheckBoxWithDescriptionControl.cs
deleted file mode 100644
index df8711fe08..0000000000
--- a/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/CheckBoxWithDescriptionControl.cs
+++ /dev/null
@@ -1,76 +0,0 @@
-// 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 System.ComponentModel;
-
-using Microsoft.UI.Xaml;
-using Microsoft.UI.Xaml.Automation;
-using Microsoft.UI.Xaml.Controls;
-
-namespace Microsoft.CmdPal.UI.Controls;
-
-public partial class CheckBoxWithDescriptionControl : CheckBox
-{
- private CheckBoxWithDescriptionControl _checkBoxSubTextControl;
-
- public CheckBoxWithDescriptionControl()
- {
- _checkBoxSubTextControl = (CheckBoxWithDescriptionControl)this;
- this.Loaded += CheckBoxSubTextControl_Loaded;
- }
-
- protected override void OnApplyTemplate()
- {
- Update();
- base.OnApplyTemplate();
- }
-
- private void Update()
- {
- if (!string.IsNullOrEmpty(Header))
- {
- AutomationProperties.SetName(this, Header);
- }
- }
-
- private void CheckBoxSubTextControl_Loaded(object sender, RoutedEventArgs e)
- {
- StackPanel panel = new StackPanel() { Orientation = Orientation.Vertical };
- panel.Children.Add(new TextBlock() { Text = Header, TextWrapping = TextWrapping.WrapWholeWords });
-
- // Add text box only if the description is not empty. Required for additional plugin options.
- if (!string.IsNullOrWhiteSpace(Description))
- {
- panel.Children.Add(new IsEnabledTextBlock() { Style = (Style)App.Current.Resources["SecondaryIsEnabledTextBlockStyle"], Text = Description });
- }
-
- _checkBoxSubTextControl.Content = panel;
- }
-
- public static readonly DependencyProperty HeaderProperty = DependencyProperty.Register(
- "Header",
- typeof(string),
- typeof(CheckBoxWithDescriptionControl),
- new PropertyMetadata(default(string)));
-
- public static readonly DependencyProperty DescriptionProperty = DependencyProperty.Register(
- "Description",
- typeof(string),
- typeof(CheckBoxWithDescriptionControl),
- new PropertyMetadata(default(string)));
-
- [Localizable(true)]
- public string Header
- {
- get => (string)GetValue(HeaderProperty);
- set => SetValue(HeaderProperty, value);
- }
-
- [Localizable(true)]
- public string Description
- {
- get => (string)GetValue(DescriptionProperty);
- set => SetValue(DescriptionProperty, value);
- }
-}
diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/IsEnabledTextBlock.xaml b/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/IsEnabledTextBlock.xaml
deleted file mode 100644
index 8218d5bf21..0000000000
--- a/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/IsEnabledTextBlock.xaml
+++ /dev/null
@@ -1,43 +0,0 @@
-
-
-
-
-
\ No newline at end of file
diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/IsEnabledTextBlock.xaml.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/IsEnabledTextBlock.xaml.cs
deleted file mode 100644
index ffe65bc9f9..0000000000
--- a/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/IsEnabledTextBlock.xaml.cs
+++ /dev/null
@@ -1,51 +0,0 @@
-// 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 System.ComponentModel;
-
-using Microsoft.UI.Xaml;
-using Microsoft.UI.Xaml.Controls;
-
-namespace Microsoft.CmdPal.UI.Controls;
-
-[TemplateVisualState(Name = "Normal", GroupName = "CommonStates")]
-[TemplateVisualState(Name = "Disabled", GroupName = "CommonStates")]
-public partial class IsEnabledTextBlock : Control
-{
- public IsEnabledTextBlock()
- {
- this.Style = (Style)App.Current.Resources["DefaultIsEnabledTextBlockStyle"];
- }
-
- protected override void OnApplyTemplate()
- {
- IsEnabledChanged -= IsEnabledTextBlock_IsEnabledChanged;
- SetEnabledState();
- IsEnabledChanged += IsEnabledTextBlock_IsEnabledChanged;
- base.OnApplyTemplate();
- }
-
- public static readonly DependencyProperty TextProperty = DependencyProperty.Register(
- "Text",
- typeof(string),
- typeof(IsEnabledTextBlock),
- null);
-
- [Localizable(true)]
- public string Text
- {
- get => (string)GetValue(TextProperty);
- set => SetValue(TextProperty, value);
- }
-
- private void IsEnabledTextBlock_IsEnabledChanged(object sender, DependencyPropertyChangedEventArgs e)
- {
- SetEnabledState();
- }
-
- private void SetEnabledState()
- {
- VisualStateManager.GoToState(this, IsEnabled ? "Normal" : "Disabled", true);
- }
-}
diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/KeyVisual/KeyVisual.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/KeyVisual/KeyVisual.cs
deleted file mode 100644
index ed7022fce9..0000000000
--- a/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/KeyVisual/KeyVisual.cs
+++ /dev/null
@@ -1,178 +0,0 @@
-// 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.UI.Xaml;
-using Microsoft.UI.Xaml.Controls;
-using Microsoft.UI.Xaml.Markup;
-using Windows.System;
-
-namespace Microsoft.CmdPal.UI.Controls;
-
-[TemplatePart(Name = KeyPresenter, Type = typeof(ContentPresenter))]
-[TemplateVisualState(Name = "Normal", GroupName = "CommonStates")]
-[TemplateVisualState(Name = "Disabled", GroupName = "CommonStates")]
-[TemplateVisualState(Name = "Default", GroupName = "StateStates")]
-[TemplateVisualState(Name = "Error", GroupName = "StateStates")]
-public sealed partial class KeyVisual : Control
-{
- private const string KeyPresenter = "KeyPresenter";
- private KeyVisual? _keyVisual;
- private ContentPresenter _keyPresenter = new();
-
- public object Content
- {
- get => GetValue(ContentProperty);
- set => SetValue(ContentProperty, value);
- }
-
- public static readonly DependencyProperty ContentProperty = DependencyProperty.Register("Content", typeof(object), typeof(KeyVisual), new PropertyMetadata(default(string), OnContentChanged));
-
- public VisualType VisualType
- {
- get => (VisualType)GetValue(VisualTypeProperty);
- set => SetValue(VisualTypeProperty, value);
- }
-
- public static readonly DependencyProperty VisualTypeProperty = DependencyProperty.Register("VisualType", typeof(VisualType), typeof(KeyVisual), new PropertyMetadata(default(VisualType), OnSizeChanged));
-
- public bool IsError
- {
- get => (bool)GetValue(IsErrorProperty);
- set => SetValue(IsErrorProperty, value);
- }
-
- public static readonly DependencyProperty IsErrorProperty = DependencyProperty.Register("IsError", typeof(bool), typeof(KeyVisual), new PropertyMetadata(false, OnIsErrorChanged));
-
- public KeyVisual()
- {
- this.DefaultStyleKey = typeof(KeyVisual);
- this.Style = GetStyleSize("TextKeyVisualStyle");
- }
-
- protected override void OnApplyTemplate()
- {
- IsEnabledChanged -= KeyVisual_IsEnabledChanged;
- _keyVisual = this;
- _keyPresenter = (ContentPresenter)_keyVisual.GetTemplateChild(KeyPresenter);
- Update();
- SetEnabledState();
- SetErrorState();
- IsEnabledChanged += KeyVisual_IsEnabledChanged;
- base.OnApplyTemplate();
- }
-
- private static void OnContentChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- ((KeyVisual)d).Update();
- }
-
- private static void OnSizeChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- ((KeyVisual)d).Update();
- }
-
- private static void OnIsErrorChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- ((KeyVisual)d).SetErrorState();
- }
-
- private void Update()
- {
- if (_keyVisual is null)
- {
- return;
- }
-
- if (_keyVisual.Content is not null)
- {
- if (_keyVisual.Content.GetType() == typeof(string))
- {
- _keyVisual.Style = GetStyleSize("TextKeyVisualStyle");
- _keyVisual._keyPresenter.Content = _keyVisual.Content;
- }
- else
- {
- _keyVisual.Style = GetStyleSize("IconKeyVisualStyle");
-
- switch ((int)_keyVisual.Content)
- {
- /* We can enable other glyphs in the future
- case 13: // The Enter key or button.
- _keyVisual._keyPresenter.Content = "\uE751"; break;
-
- case 8: // The Back key or button.
- _keyVisual._keyPresenter.Content = "\uE750"; break;
-
- case 16: // The right Shift key or button.
- case 160: // The left Shift key or button.
- case 161: // The Shift key or button.
- _keyVisual._keyPresenter.Content = "\uE752"; break; */
-
- case 38: _keyVisual._keyPresenter.Content = "\uE0E4"; break; // The Up Arrow key or button.
- case 40: _keyVisual._keyPresenter.Content = "\uE0E5"; break; // The Down Arrow key or button.
- case 37: _keyVisual._keyPresenter.Content = "\uE0E2"; break; // The Left Arrow key or button.
- case 39: _keyVisual._keyPresenter.Content = "\uE0E3"; break; // The Right Arrow key or button.
-
- case 91: // The left Windows key
- case 92: // The right Windows key
- var winIcon = XamlReader.Load(@"") as PathIcon;
- var winIconContainer = new Viewbox
- {
- Child = winIcon,
- HorizontalAlignment = HorizontalAlignment.Center,
- VerticalAlignment = VerticalAlignment.Center,
- };
-
- var iconDimensions = GetIconSize();
- winIconContainer.Height = iconDimensions;
- winIconContainer.Width = iconDimensions;
- _keyVisual._keyPresenter.Content = winIconContainer;
- break;
- default: _keyVisual._keyPresenter.Content = ((VirtualKey)_keyVisual.Content).ToString(); break;
- }
- }
- }
- }
-
- public Style GetStyleSize(string styleName)
- {
- return VisualType == VisualType.Small
- ? (Style)App.Current.Resources["Small" + styleName]
- : VisualType == VisualType.SmallOutline
- ? (Style)App.Current.Resources["SmallOutline" + styleName]
- : VisualType == VisualType.TextOnly
- ? (Style)App.Current.Resources["Only" + styleName]
- : (Style)App.Current.Resources["Default" + styleName];
- }
-
- public double GetIconSize()
- {
- return VisualType == VisualType.Small || VisualType == VisualType.SmallOutline
- ? (double)App.Current.Resources["SmallIconSize"]
- : (double)App.Current.Resources["DefaultIconSize"];
- }
-
- private void KeyVisual_IsEnabledChanged(object sender, DependencyPropertyChangedEventArgs e)
- {
- SetEnabledState();
- }
-
- private void SetErrorState()
- {
- VisualStateManager.GoToState(this, IsError ? "Error" : "Default", true);
- }
-
- private void SetEnabledState()
- {
- VisualStateManager.GoToState(this, IsEnabled ? "Normal" : "Disabled", true);
- }
-}
-
-public enum VisualType
-{
- Small,
- SmallOutline,
- TextOnly,
- Large,
-}
diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/KeyVisual/KeyVisual.xaml b/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/KeyVisual/KeyVisual.xaml
deleted file mode 100644
index 7364ea8eec..0000000000
--- a/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/KeyVisual/KeyVisual.xaml
+++ /dev/null
@@ -1,174 +0,0 @@
-
-
- 16
- 12
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/ShortcutControl/ShortcutControl.xaml b/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/ShortcutControl/ShortcutControl.xaml
index f470c54791..be70b0ca08 100644
--- a/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/ShortcutControl/ShortcutControl.xaml
+++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/ShortcutControl/ShortcutControl.xaml
@@ -5,49 +5,90 @@
xmlns:controls="using:Microsoft.CmdPal.UI.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+ xmlns:ptcontrols="using:Microsoft.PowerToys.Common.UI.Controls"
x:Name="LayoutRoot"
d:DesignHeight="300"
d:DesignWidth="400"
mc:Ignorable="d">
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/ShortcutControl/ShortcutControl.xaml.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/ShortcutControl/ShortcutControl.xaml.cs
index e7fa721277..b8aad6c323 100644
--- a/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/ShortcutControl/ShortcutControl.xaml.cs
+++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/ShortcutControl/ShortcutControl.xaml.cs
@@ -11,6 +11,7 @@ using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Automation;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Input;
+using Microsoft.Windows.ApplicationModel.Resources;
using Windows.System;
namespace Microsoft.CmdPal.UI.Controls;
@@ -36,6 +37,8 @@ public sealed partial class ShortcutControl : UserControl, IDisposable, IRecipie
public static readonly DependencyProperty AllowDisableProperty = DependencyProperty.Register("AllowDisable", typeof(bool), typeof(ShortcutControl), new PropertyMetadata(false, OnAllowDisableChanged));
+ private static ResourceLoader resourceLoader = Microsoft.CmdPal.UI.Helpers.ResourceLoaderInstance.ResourceLoader;
+
private static void OnAllowDisableChanged(DependencyObject d, DependencyPropertyChangedEventArgs? e)
{
var me = d as ShortcutControl;
@@ -96,8 +99,7 @@ public sealed partial class ShortcutControl : UserControl, IDisposable, IRecipie
{
hotkeySettings = value;
SetValue(HotkeySettingsProperty, value);
- PreviewKeysControl.ItemsSource = HotkeySettings?.GetKeysList() ?? new List