From fcef988aab5c6a28962a96348853001ad4a821c1 Mon Sep 17 00:00:00 2001 From: mantaionut Date: Mon, 27 Jan 2025 10:05:17 +0200 Subject: [PATCH 01/11] Initial implementation --- .../colorPicker/ColorPickerUI/App.xaml | 3 +- .../ColorPickerUI/ColorEditorWindow.xaml | 21 +---- .../ColorPickerUI/ColorEditorWindow.xaml.cs | 7 +- .../ColorPickerUI/ColorPickerUI.csproj | 1 - .../Controls/ColorFormatControl.xaml | 11 ++- .../Controls/ColorPickerControl.xaml | 77 ++++++++++--------- .../Controls/ColorPickerControl.xaml.cs | 32 ++++---- .../ColorPickerUI/Helpers/AppStateHandler.cs | 8 -- .../ColorPickerUI/MainWindow.xaml.cs | 2 - .../ColorPickerUI/Views/ColorEditorView.xaml | 69 ++++++++++------- .../ColorPickerUI/Views/ZoomView.xaml | 2 +- 11 files changed, 110 insertions(+), 123 deletions(-) diff --git a/src/modules/colorPicker/ColorPickerUI/App.xaml b/src/modules/colorPicker/ColorPickerUI/App.xaml index a6e26f31e2cd..ee2bb811c313 100644 --- a/src/modules/colorPicker/ColorPickerUI/App.xaml +++ b/src/modules/colorPicker/ColorPickerUI/App.xaml @@ -3,12 +3,11 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml" + ThemeMode="System" StartupUri="MainWindow.xaml"> - - diff --git a/src/modules/colorPicker/ColorPickerUI/ColorEditorWindow.xaml b/src/modules/colorPicker/ColorPickerUI/ColorEditorWindow.xaml index e8ec0a0a7a56..6cc9f20c9462 100644 --- a/src/modules/colorPicker/ColorPickerUI/ColorEditorWindow.xaml +++ b/src/modules/colorPicker/ColorPickerUI/ColorEditorWindow.xaml @@ -1,4 +1,4 @@ - @@ -27,21 +24,9 @@ - - - - - - + diff --git a/src/modules/colorPicker/ColorPickerUI/ColorEditorWindow.xaml.cs b/src/modules/colorPicker/ColorPickerUI/ColorEditorWindow.xaml.cs index 323fa77b5e31..3141e59cca52 100644 --- a/src/modules/colorPicker/ColorPickerUI/ColorEditorWindow.xaml.cs +++ b/src/modules/colorPicker/ColorPickerUI/ColorEditorWindow.xaml.cs @@ -3,25 +3,22 @@ // See the LICENSE file in the project root for more information. using System; - +using System.Windows; using ColorPicker.Helpers; using ManagedCommon; -using Wpf.Ui.Controls; namespace ColorPicker { /// /// Interaction logic for ColorEditorWindow.xaml /// - public partial class ColorEditorWindow : FluentWindow + public partial class ColorEditorWindow : Window { private readonly AppStateHandler _appStateHandler; public ColorEditorWindow(AppStateHandler appStateHandler) { InitializeComponent(); - Wpf.Ui.Appearance.SystemThemeWatcher.Watch(this); - WindowBackdropType = OSVersionHelper.IsWindows11() ? WindowBackdropType.Mica : WindowBackdropType = WindowBackdropType.None; _appStateHandler = appStateHandler; Closing += ColorEditorWindow_Closing; diff --git a/src/modules/colorPicker/ColorPickerUI/ColorPickerUI.csproj b/src/modules/colorPicker/ColorPickerUI/ColorPickerUI.csproj index 827f479e376b..d1c55e3db7f5 100644 --- a/src/modules/colorPicker/ColorPickerUI/ColorPickerUI.csproj +++ b/src/modules/colorPicker/ColorPickerUI/ColorPickerUI.csproj @@ -38,7 +38,6 @@ - diff --git a/src/modules/colorPicker/ColorPickerUI/Controls/ColorFormatControl.xaml b/src/modules/colorPicker/ColorPickerUI/Controls/ColorFormatControl.xaml index b2b398b5c631..951d8ae77c7c 100644 --- a/src/modules/colorPicker/ColorPickerUI/Controls/ColorFormatControl.xaml +++ b/src/modules/colorPicker/ColorPickerUI/Controls/ColorFormatControl.xaml @@ -66,7 +66,6 @@ HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}" IsDeferredScrollingEnabled="{TemplateBinding ScrollViewer.IsDeferredScrollingEnabled}" IsTabStop="{TemplateBinding ScrollViewer.IsTabStop}" - Style="{StaticResource DefaultTextBoxScrollViewerStyle}" TextElement.Foreground="{TemplateBinding Foreground}" VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}" /> @@ -129,10 +128,7 @@ Height="48" Margin="0,0,0,8" HorizontalAlignment="Stretch" - Background="{DynamicResource CardBackgroundFillColorDefaultBrush}" - BorderBrush="{DynamicResource CardStrokeColorDefaultBrush}" - BorderThickness="1" - CornerRadius="{DynamicResource ControlCornerRadius}"> + BorderThickness="1"> @@ -173,7 +169,10 @@ Style="{StaticResource SubtleButtonStyle}" ToolTipService.ToolTip="{x:Static p:Resources.Copy_to_clipboard}"> - + diff --git a/src/modules/colorPicker/ColorPickerUI/Controls/ColorPickerControl.xaml b/src/modules/colorPicker/ColorPickerUI/Controls/ColorPickerControl.xaml index d66923ddb29c..dfb6a66bfb42 100644 --- a/src/modules/colorPicker/ColorPickerUI/Controls/ColorPickerControl.xaml +++ b/src/modules/colorPicker/ColorPickerUI/Controls/ColorPickerControl.xaml @@ -213,13 +213,23 @@ Style="{DynamicResource ColorShadeButtonStyle}" ToolTipService.ToolTip="{x:Static p:Resources.Selected_color_tooltip}"> - - + + + + + + + + @@ -317,38 +327,27 @@ Text="RGB" TextAlignment="Center" /> - - - - - - + + + + - - - + + + + diff --git a/src/modules/colorPicker/ColorPickerUI/Controls/ColorPickerControl.xaml.cs b/src/modules/colorPicker/ColorPickerUI/Controls/ColorPickerControl.xaml.cs index 9b189e893ee1..fe90211ba8f1 100644 --- a/src/modules/colorPicker/ColorPickerUI/Controls/ColorPickerControl.xaml.cs +++ b/src/modules/colorPicker/ColorPickerUI/Controls/ColorPickerControl.xaml.cs @@ -14,7 +14,6 @@ using ColorPicker.Helpers; using ManagedCommon; -using Wpf.Ui.Controls; using static System.Net.Mime.MediaTypeNames; @@ -76,9 +75,9 @@ private static void SelectedColorPropertyChanged(DependencyObject d, DependencyP control._ignoreRGBChanges = true; control.HexCode.Text = ColorToHex(newColor); - control.RNumberBox.Value = newColor.R; - control.GNumberBox.Value = newColor.G; - control.BNumberBox.Value = newColor.B; + control.RNumberBox.Text = newColor.R.ToString(CultureInfo.InvariantCulture); + control.GNumberBox.Text = newColor.G.ToString(CultureInfo.InvariantCulture); + control.BNumberBox.Text = newColor.B.ToString(CultureInfo.InvariantCulture); control.SetColorFromTextBoxes(System.Drawing.Color.FromArgb(newColor.R, newColor.G, newColor.B)); control._ignoreRGBChanges = false; @@ -175,9 +174,9 @@ private void UpdateTextBoxesAndCurrentColor(Color currentColor) if (!_ignoreRGBChanges) { - RNumberBox.Value = currentColor.R; - GNumberBox.Value = currentColor.G; - BNumberBox.Value = currentColor.B; + RNumberBox.Text = currentColor.R.ToString(CultureInfo.InvariantCulture); + GNumberBox.Text = currentColor.G.ToString(CultureInfo.InvariantCulture); + BNumberBox.Text = currentColor.B.ToString(CultureInfo.InvariantCulture); } _currentColor = currentColor; @@ -231,7 +230,7 @@ private void OKButton_Click(object sender, RoutedEventArgs e) { SelectedColorChangedCommand.Execute(_currentColor); SessionEventHelper.Event.EditorColorAdjusted = true; - DetailsFlyout.Hide(); + DetailsFlyout.IsOpen = false; } private void DetailsFlyout_Closed(object sender, object e) @@ -361,11 +360,10 @@ private void RGBNumberBox_TextChanged(object sender, TextChangedEventArgs e) { if (!_ignoreRGBChanges) { - var numberBox = sender as NumberBox; - - byte r = numberBox.Name == "RNumberBox" ? GetValueFromNumberBox(numberBox) : (byte)RNumberBox.Value; - byte g = numberBox.Name == "GNumberBox" ? GetValueFromNumberBox(numberBox) : (byte)GNumberBox.Value; - byte b = numberBox.Name == "BNumberBox" ? GetValueFromNumberBox(numberBox) : (byte)BNumberBox.Value; + var numberBox = sender as TextBox; + byte r = GetValueFromNumberBox(RNumberBox); + byte g = GetValueFromNumberBox(GNumberBox); + byte b = GetValueFromNumberBox(BNumberBox); _ignoreRGBChanges = true; SetColorFromTextBoxes(System.Drawing.Color.FromArgb(r, g, b)); @@ -379,22 +377,24 @@ private void RGBNumberBox_TextChanged(object sender, TextChangedEventArgs e) /// /// numberBox control which value we want to get /// Validated value as per numberbox conditions, if content is invalid it returns previous value - private static byte GetValueFromNumberBox(NumberBox numberBox) + private static byte GetValueFromNumberBox(TextBox numberBox) { + int minimum = 0; + int maximum = 255; double? parsedValue = ParseDouble(numberBox.Text); if (parsedValue != null) { var parsedValueByte = (byte)parsedValue; - if (parsedValueByte >= numberBox.Minimum && parsedValueByte <= numberBox.Maximum) + if (parsedValueByte >= minimum && parsedValueByte <= maximum) { return parsedValueByte; } } // not valid input, return previous value - return (byte)numberBox.Value; + return 0; } public static double? ParseDouble(string text) diff --git a/src/modules/colorPicker/ColorPickerUI/Helpers/AppStateHandler.cs b/src/modules/colorPicker/ColorPickerUI/Helpers/AppStateHandler.cs index 09d2aa4d54de..4940bd75e3ad 100644 --- a/src/modules/colorPicker/ColorPickerUI/Helpers/AppStateHandler.cs +++ b/src/modules/colorPicker/ColorPickerUI/Helpers/AppStateHandler.cs @@ -138,14 +138,6 @@ private void ShowColorPicker() Application.Current.MainWindow.Opacity = 0; Application.Current.MainWindow.Visibility = Visibility.Visible; _colorPickerShown = true; - - // HACK: WPF UI theme watcher removes the composition target background color, among other weird stuff. - // https://github.com/lepoco/wpfui/blob/303f0aefcd59a142bc681415dc4360a34a15f33d/src/Wpf.Ui/Controls/Window/WindowBackdrop.cs#L280 - // So we set it back with https://github.com/lepoco/wpfui/blob/303f0aefcd59a142bc681415dc4360a34a15f33d/src/Wpf.Ui/Controls/Window/WindowBackdrop.cs#L191 - // And also reapply the intended backdrop. - // This hack fixes: https://github.com/microsoft/PowerToys/issues/31725 - Wpf.Ui.Controls.WindowBackdrop.RemoveBackground(Application.Current.MainWindow); - Wpf.Ui.Controls.WindowBackdrop.ApplyBackdrop(Application.Current.MainWindow, Wpf.Ui.Controls.WindowBackdropType.None); } } diff --git a/src/modules/colorPicker/ColorPickerUI/MainWindow.xaml.cs b/src/modules/colorPicker/ColorPickerUI/MainWindow.xaml.cs index ed9feae896a1..7f16c6055e4b 100644 --- a/src/modules/colorPicker/ColorPickerUI/MainWindow.xaml.cs +++ b/src/modules/colorPicker/ColorPickerUI/MainWindow.xaml.cs @@ -7,7 +7,6 @@ using System.Windows.Interop; using ColorPicker.ViewModelContracts; -using Wpf.Ui.Controls; namespace ColorPicker { @@ -20,7 +19,6 @@ public MainWindow() { Closing += MainWindow_Closing; Bootstrapper.InitializeContainer(this); - Wpf.Ui.Appearance.SystemThemeWatcher.Watch(this, WindowBackdropType.None); InitializeComponent(); DataContext = this; Show(); // Call show just to make sure source is initialized at startup. diff --git a/src/modules/colorPicker/ColorPickerUI/Views/ColorEditorView.xaml b/src/modules/colorPicker/ColorPickerUI/Views/ColorEditorView.xaml index d63f83a40b20..ad81b6b28af5 100644 --- a/src/modules/colorPicker/ColorPickerUI/Views/ColorEditorView.xaml +++ b/src/modules/colorPicker/ColorPickerUI/Views/ColorEditorView.xaml @@ -22,21 +22,25 @@ - - - - - - + - + - + - + - + @@ -195,7 +207,10 @@ TabIndex="2" ToolTipService.ToolTip="{x:Static p:Resources.Open_settings}"> - + @@ -263,7 +278,10 @@ VerticalAlignment="Center" Orientation="Vertical" Visibility="{Binding ColorsHistory.Count, Converter={StaticResource numberToInvertedVisibilityConverter}}"> - + - - - - - + Text="" /> - + Text="" /> From 7afe2f6c8dbf5836b401b5f972e0e965c5fd70ac Mon Sep 17 00:00:00 2001 From: mantaionut Date: Mon, 27 Jan 2025 14:14:45 +0200 Subject: [PATCH 02/11] fix style --- src/modules/colorPicker/ColorPickerUI/App.xaml | 1 - .../ColorPickerUI/ColorEditorWindow.xaml | 3 +-- .../ColorPickerUI/Controls/ColorFormatControl.xaml | 6 ++++-- .../ColorPickerUI/Controls/ColorPickerControl.xaml | 14 +++++++------- .../ColorPickerUI/Resources/Styles.xaml | 4 +++- .../ColorPickerUI/Views/ColorEditorView.xaml | 2 -- .../colorPicker/ColorPickerUI/Views/ZoomView.xaml | 1 - 7 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/modules/colorPicker/ColorPickerUI/App.xaml b/src/modules/colorPicker/ColorPickerUI/App.xaml index ee2bb811c313..00929b9947c2 100644 --- a/src/modules/colorPicker/ColorPickerUI/App.xaml +++ b/src/modules/colorPicker/ColorPickerUI/App.xaml @@ -2,7 +2,6 @@ x:Class="ColorPickerUI.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" - xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml" ThemeMode="System" StartupUri="MainWindow.xaml"> diff --git a/src/modules/colorPicker/ColorPickerUI/ColorEditorWindow.xaml b/src/modules/colorPicker/ColorPickerUI/ColorEditorWindow.xaml index 6cc9f20c9462..47bd4619f612 100644 --- a/src/modules/colorPicker/ColorPickerUI/ColorEditorWindow.xaml +++ b/src/modules/colorPicker/ColorPickerUI/ColorEditorWindow.xaml @@ -7,10 +7,9 @@ xmlns:e="http://schemas.microsoft.com/xaml/behaviors" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:p="clr-namespace:ColorPicker.Properties" - xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml" Width="440" Height="380" - + AutomationProperties.Name="{x:Static p:Resources.cp_editor}" ResizeMode="NoResize" Topmost="True" diff --git a/src/modules/colorPicker/ColorPickerUI/Controls/ColorFormatControl.xaml b/src/modules/colorPicker/ColorPickerUI/Controls/ColorFormatControl.xaml index 951d8ae77c7c..c187361f6d57 100644 --- a/src/modules/colorPicker/ColorPickerUI/Controls/ColorFormatControl.xaml +++ b/src/modules/colorPicker/ColorPickerUI/Controls/ColorFormatControl.xaml @@ -6,7 +6,6 @@ xmlns:local="clr-namespace:ColorPicker" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:p="clr-namespace:ColorPicker.Properties" - xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml" mc:Ignorable="d"> +