[QuickAccent]Move from ModernWPF to WpfUi (#29863)

* Updating to WpfUI

* XAML styler

* Removing unused namespaces

* Updating ImageResizer watcher
This commit is contained in:
Niels Laute
2023-11-16 18:40:04 +01:00
committed by GitHub
parent 7e0f69f7d4
commit 7d9681ecd2
12 changed files with 91 additions and 292 deletions

View File

@@ -2,15 +2,14 @@
x:Class="PowerAccent.UI.App" x:Class="PowerAccent.UI.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:PowerAccent" xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
xmlns:ui="http://schemas.modernwpf.com/2019"
StartupUri="Selector.xaml"> StartupUri="Selector.xaml">
<Application.Resources> <Application.Resources>
<ResourceDictionary> <ResourceDictionary>
<ResourceDictionary.MergedDictionaries> <ResourceDictionary.MergedDictionaries>
<ui:ThemeResources /> <ui:ThemesDictionary Theme="Dark" />
<ui:XamlControlsResources /> <ui:ControlsDictionary />
</ResourceDictionary.MergedDictionaries> </ResourceDictionary.MergedDictionaries>
<!-- Other app resources here --> <!-- Other app resources here -->
</ResourceDictionary> </ResourceDictionary>

View File

@@ -5,9 +5,7 @@
using System; using System;
using System.Threading; using System.Threading;
using System.Windows; using System.Windows;
using Common.UI;
using ManagedCommon; using ManagedCommon;
using PowerAccent.Core.Tools;
namespace PowerAccent.UI namespace PowerAccent.UI
{ {
@@ -18,7 +16,6 @@ namespace PowerAccent.UI
{ {
private static Mutex _mutex; private static Mutex _mutex;
private bool _disposed; private bool _disposed;
private ThemeManager _themeManager;
protected override void OnStartup(StartupEventArgs e) protected override void OnStartup(StartupEventArgs e)
{ {
@@ -30,7 +27,6 @@ namespace PowerAccent.UI
Application.Current.Shutdown(); Application.Current.Shutdown();
} }
_themeManager = new ThemeManager(this);
base.OnStartup(e); base.OnStartup(e);
} }
@@ -50,7 +46,6 @@ namespace PowerAccent.UI
if (disposing) if (disposing)
{ {
_mutex?.Dispose(); _mutex?.Dispose();
_themeManager?.Dispose();
} }
_disposed = true; _disposed = true;

View File

@@ -35,7 +35,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.Windows.CsWinRT" /> <PackageReference Include="Microsoft.Windows.CsWinRT" />
<PackageReference Include="ModernWpfUI" /> <PackageReference Include="WPF-UI" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@@ -9,7 +9,6 @@ using System.Threading.Tasks;
using System.Windows; using System.Windows;
using interop; using interop;
using ManagedCommon; using ManagedCommon;
using PowerAccent.Core.Tools;
namespace PowerAccent.UI; namespace PowerAccent.UI;

View File

@@ -1,30 +1,30 @@
<Window <ui:FluentWindow
x:Class="PowerAccent.UI.Selector" x:Class="PowerAccent.UI.Selector"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:PowerAccent.UI"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ui="http://schemas.modernwpf.com/2019" xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
Title="MainWindow" Title="MainWindow"
Height="120"
MinWidth="600" MinWidth="600"
AllowsTransparency="True" MinHeight="0"
Background="Transparent" ui:Design.Background="{DynamicResource ApplicationBackgroundBrush}"
DataContext="{Binding RelativeSource={RelativeSource Self}}" DataContext="{Binding RelativeSource={RelativeSource Self}}"
ExtendsContentIntoTitleBar="True"
ResizeMode="NoResize" ResizeMode="NoResize"
ShowInTaskbar="False" ShowInTaskbar="False"
SizeToContent="WidthAndHeight" SizeToContent="WidthAndHeight"
Visibility="Collapsed" Visibility="Collapsed"
WindowBackdropType="None"
WindowStyle="None" WindowStyle="None"
mc:Ignorable="d"> mc:Ignorable="d">
<Window.Resources> <ui:FluentWindow.Resources>
<DataTemplate x:Key="DefaultKeyTemplate"> <DataTemplate x:Key="DefaultKeyTemplate">
<TextBlock <TextBlock
VerticalAlignment="Center" VerticalAlignment="Center"
FontSize="18" FontSize="18"
Foreground="{DynamicResource PrimaryForegroundBrush}" Foreground="{DynamicResource TextFillColorPrimaryBrush}"
Text="{Binding}" Text="{Binding}"
TextAlignment="Center" /> TextAlignment="Center" />
</DataTemplate> </DataTemplate>
@@ -33,101 +33,89 @@
<TextBlock <TextBlock
VerticalAlignment="Center" VerticalAlignment="Center"
FontSize="18" FontSize="18"
Foreground="White" Foreground="{DynamicResource TextOnAccentFillColorPrimaryBrush}"
Text="{Binding}" Text="{Binding}"
TextAlignment="Center" /> TextAlignment="Center" />
</DataTemplate> </DataTemplate>
</Window.Resources> </ui:FluentWindow.Resources>
<Grid> <Grid>
<Border <Grid.RowDefinitions>
x:Name="gridBorder" <RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<ListBox
x:Name="characters"
HorizontalAlignment="Center" HorizontalAlignment="Center"
VerticalAlignment="Center" HorizontalContentAlignment="Stretch"
Background="{DynamicResource SecondaryBackgroundBrush}" VerticalContentAlignment="Stretch"
BorderBrush="{DynamicResource WindowsBorderBrush}" Background="Transparent"
BorderThickness="1" IsHitTestVisible="False">
CornerRadius="8"> <ListBox.ItemContainerStyle>
<Border.Effect> <Style TargetType="ListBoxItem">
<DropShadowEffect <Setter Property="ContentTemplate" Value="{StaticResource DefaultKeyTemplate}" />
BlurRadius="32" <Setter Property="Template">
Opacity="0.28" <Setter.Value>
ShadowDepth="1" /> <ControlTemplate TargetType="{x:Type ListBoxItem}">
</Border.Effect> <Grid
<Grid> Width="48"
<Grid.RowDefinitions> Height="48"
<RowDefinition Height="Auto" /> Margin="0"
<RowDefinition Height="Auto" /> HorizontalAlignment="Center"
</Grid.RowDefinitions> VerticalAlignment="Center"
<Border Background="{DynamicResource PrimaryBackgroundBrush}" CornerRadius="8"> SnapsToDevicePixels="true">
<ListBox <Rectangle
x:Name="characters" x:Name="SelectionIndicator"
HorizontalAlignment="Center" Margin="7"
HorizontalContentAlignment="Stretch" HorizontalAlignment="Stretch"
VerticalContentAlignment="Stretch" VerticalAlignment="Stretch"
Background="Transparent" RadiusX="4"
IsHitTestVisible="False"> RadiusY="4"
<ListBox.ItemContainerStyle> Stroke="{DynamicResource AccentControlElevationBorderBrush}"
<Style TargetType="ListBoxItem"> StrokeThickness="1"
<Setter Property="ContentTemplate" Value="{StaticResource DefaultKeyTemplate}" /> Visibility="Collapsed">
<Setter Property="Template"> <Rectangle.Fill>
<Setter.Value> <SolidColorBrush Color="{DynamicResource SystemAccentColorPrimary}" />
<ControlTemplate TargetType="{x:Type ListBoxItem}"> </Rectangle.Fill>
<Grid </Rectangle>
Width="48" <ContentPresenter Margin="12" />
Height="48"
Margin="0"
HorizontalAlignment="Center"
VerticalAlignment="Center"
SnapsToDevicePixels="true"
Style="{DynamicResource borderContent}">
<Rectangle
x:Name="SelectionIndicator"
Margin="7"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Fill="{DynamicResource SystemControlBackgroundAccentBrush}"
RadiusX="4"
RadiusY="4"
Visibility="Collapsed" />
<ContentPresenter Margin="12" />
</Grid> </Grid>
<ControlTemplate.Triggers> <ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="true"> <Trigger Property="IsSelected" Value="true">
<Setter TargetName="SelectionIndicator" Property="Visibility" Value="Visible" /> <Setter TargetName="SelectionIndicator" Property="Visibility" Value="Visible" />
<Setter Property="ContentTemplate" Value="{StaticResource SelectedKeyTemplate}" /> <Setter Property="ContentTemplate" Value="{StaticResource SelectedKeyTemplate}" />
</Trigger> </Trigger>
</ControlTemplate.Triggers> </ControlTemplate.Triggers>
</ControlTemplate> </ControlTemplate>
</Setter.Value> </Setter.Value>
</Setter> </Setter>
</Style> </Style>
</ListBox.ItemContainerStyle> </ListBox.ItemContainerStyle>
<ListBox.ItemsPanel> <ListBox.ItemsPanel>
<ItemsPanelTemplate> <ItemsPanelTemplate>
<VirtualizingStackPanel IsItemsHost="False" Orientation="Horizontal" /> <VirtualizingStackPanel IsItemsHost="False" Orientation="Horizontal" />
</ItemsPanelTemplate> </ItemsPanelTemplate>
</ListBox.ItemsPanel> </ListBox.ItemsPanel>
</ListBox> </ListBox>
</Border>
<Grid Grid.Row="1" Visibility="{Binding CharacterNameVisibility, UpdateSourceTrigger=PropertyChanged}"> <Grid
<TextBlock Grid.Row="1"
x:Name="characterName" Background="{DynamicResource LayerOnAcrylicFillColorDefaultBrush}"
Margin="8" Visibility="{Binding CharacterNameVisibility, UpdateSourceTrigger=PropertyChanged}">
FontSize="12" <TextBlock
Foreground="{DynamicResource SecondaryForegroundBrush}" x:Name="characterName"
Text="(U+0000) A COOL LETTER NAME COMES HERE" Margin="8"
TextAlignment="Center" /> FontSize="12"
<Rectangle Foreground="{DynamicResource TextFillColorSecondaryBrush}"
Height="1" Text="(U+0000) A COOL LETTER NAME COMES HERE"
HorizontalAlignment="Stretch" TextAlignment="Center" />
VerticalAlignment="Top" <Rectangle
Fill="{DynamicResource DividerBorderBrush}" /> Height="1"
</Grid> HorizontalAlignment="Stretch"
</Grid> VerticalAlignment="Top"
</Border> Fill="{DynamicResource DividerStrokeColorDefaultBrush}" />
</Grid>
</Grid> </Grid>
</Window> </ui:FluentWindow>

View File

@@ -5,13 +5,13 @@
using System; using System;
using System.ComponentModel; using System.ComponentModel;
using System.Windows; using System.Windows;
using PowerAccent.Core.Services; using Wpf.Ui.Controls;
using Point = PowerAccent.Core.Point; using Point = PowerAccent.Core.Point;
using Size = PowerAccent.Core.Size; using Size = PowerAccent.Core.Size;
namespace PowerAccent.UI; namespace PowerAccent.UI;
public partial class Selector : Window, IDisposable, INotifyPropertyChanged public partial class Selector : FluentWindow, IDisposable, INotifyPropertyChanged
{ {
private readonly Core.PowerAccent _powerAccent = new(); private readonly Core.PowerAccent _powerAccent = new();
@@ -38,6 +38,7 @@ public partial class Selector : Window, IDisposable, INotifyPropertyChanged
public Selector() public Selector()
{ {
InitializeComponent(); InitializeComponent();
Wpf.Ui.Appearance.SystemThemeWatcher.Watch(this);
Application.Current.MainWindow.ShowActivated = false; Application.Current.MainWindow.ShowActivated = false;
Application.Current.MainWindow.Topmost = true; Application.Current.MainWindow.Topmost = true;
} }
@@ -67,7 +68,6 @@ public partial class Selector : Window, IDisposable, INotifyPropertyChanged
characters.SelectedIndex = _selectedIndex; characters.SelectedIndex = _selectedIndex;
this.UpdateLayout(); // Required for filling the actual width/height before positioning. this.UpdateLayout(); // Required for filling the actual width/height before positioning.
SetWindowPosition(); SetWindowPosition();
SetWindowAlignment();
Show(); Show();
Microsoft.PowerToys.Telemetry.PowerToysTelemetry.Log.WriteEvent(new PowerAccent.Core.Telemetry.PowerAccentShowAccentMenuEvent()); Microsoft.PowerToys.Telemetry.PowerToysTelemetry.Log.WriteEvent(new PowerAccent.Core.Telemetry.PowerAccentShowAccentMenuEvent());
} }
@@ -90,17 +90,6 @@ public partial class Selector : Window, IDisposable, INotifyPropertyChanged
this.Top = position.Y; this.Top = position.Y;
} }
private void SetWindowAlignment()
{
gridBorder.HorizontalAlignment = _powerAccent.GetToolbarPosition() switch
{
Position.Left or Position.TopLeft or Position.BottomLeft => HorizontalAlignment.Left,
Position.Right or Position.TopRight or Position.BottomRight => HorizontalAlignment.Right,
Position.Center or Position.Top or Position.Bottom => HorizontalAlignment.Center,
_ => HorizontalAlignment.Center,
};
}
protected override void OnClosed(EventArgs e) protected override void OnClosed(EventArgs e)
{ {
_powerAccent.Dispose(); _powerAccent.Dispose();

View File

@@ -1,32 +0,0 @@
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=System.Runtime">
<!-- Metadata -->
<system:String x:Key="Theme.Name">Dark.Accent1</system:String>
<system:String x:Key="Theme.Origin">PowerToysRun</system:String>
<system:String x:Key="Theme.DisplayName">Accent1 (Dark)</system:String>
<system:String x:Key="Theme.BaseColorScheme">Dark</system:String>
<system:String x:Key="Theme.ColorScheme">Accent1</system:String>
<Color x:Key="Theme.PrimaryAccentColor">Black</Color>
<SolidColorBrush x:Key="SecondaryBackgroundBrush" Color="#FF1c1c1c" />
<SolidColorBrush
x:Key="PrimaryBackgroundBrush"
Opacity="0.3"
Color="#FF3A3A3A" />
<SolidColorBrush
x:Key="WindowBorderBrush"
Opacity="0.4"
Color="#FF757575" />
<SolidColorBrush
x:Key="DividerBorderBrush"
Opacity="0.0837"
Color="#FFFFFFFF" />
<SolidColorBrush x:Key="PrimaryForegroundBrush" Color="#FFFFFFFF" />
<SolidColorBrush
x:Key="SecondaryForegroundBrush"
Opacity="0.5442"
Color="#FFFFFFFF" />
</ResourceDictionary>

View File

@@ -1,26 +0,0 @@
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=System.Runtime">
<!-- Metadata -->
<system:String x:Key="Theme.Name">HighContrast.Accent2</system:String>
<system:String x:Key="Theme.Origin">PowerToysRun</system:String>
<system:String x:Key="Theme.DisplayName">Accent2 (HighContrast)</system:String>
<system:String x:Key="Theme.BaseColorScheme">HighContrast</system:String>
<system:String x:Key="Theme.ColorScheme">Accent2</system:String>
<Color x:Key="Theme.PrimaryAccentColor">White</Color>
<SolidColorBrush x:Key="SecondaryBackgroundBrush" Color="#FF1c1c1c" />
<SolidColorBrush
x:Key="PrimaryBackgroundBrush"
Opacity="0.3"
Color="#FF3A3A3A" />
<SolidColorBrush x:Key="WindowBorderBrush" Color="#FFffff00" />
<SolidColorBrush
x:Key="DividerBorderBrush"
Opacity="0.0837"
Color="#FFFFFFFF" />
<SolidColorBrush x:Key="PrimaryForegroundBrush" Color="#FFffff00" />
<SolidColorBrush x:Key="SecondaryForegroundBrush" Color="#FF00ff00" />
</ResourceDictionary>

View File

@@ -1,26 +0,0 @@
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=System.Runtime">
<!-- Metadata -->
<system:String x:Key="Theme.Name">HighContrast.Accent3</system:String>
<system:String x:Key="Theme.Origin">PowerToysRun</system:String>
<system:String x:Key="Theme.DisplayName">Accent3 (HighContrast)</system:String>
<system:String x:Key="Theme.BaseColorScheme">HighContrast</system:String>
<system:String x:Key="Theme.ColorScheme">Accent3</system:String>
<Color x:Key="Theme.PrimaryAccentColor">White</Color>
<SolidColorBrush x:Key="SecondaryBackgroundBrush" Color="#FF1c1c1c" />
<SolidColorBrush
x:Key="PrimaryBackgroundBrush"
Opacity="0.3"
Color="#FF3A3A3A" />
<SolidColorBrush x:Key="WindowBorderBrush" Color="#FF00ff00" />
<SolidColorBrush
x:Key="DividerBorderBrush"
Opacity="0.0837"
Color="#FFFFFFFF" />
<SolidColorBrush x:Key="PrimaryForegroundBrush" Color="#FF00ff00" />
<SolidColorBrush x:Key="SecondaryForegroundBrush" Color="#FFc0c0c0" />
</ResourceDictionary>

View File

@@ -1,26 +0,0 @@
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=System.Runtime">
<!-- Metadata -->
<system:String x:Key="Theme.Name">HighContrast.Accent4</system:String>
<system:String x:Key="Theme.Origin">PowerToysRun</system:String>
<system:String x:Key="Theme.DisplayName">Accent4 (HighContrast)</system:String>
<system:String x:Key="Theme.BaseColorScheme">HighContrast</system:String>
<system:String x:Key="Theme.ColorScheme">Accent4</system:String>
<Color x:Key="Theme.PrimaryAccentColor">White</Color>
<SolidColorBrush x:Key="SecondaryBackgroundBrush" Color="#FF1c1c1c" />
<SolidColorBrush
x:Key="PrimaryBackgroundBrush"
Opacity="0.3"
Color="#FF3A3A3A" />
<SolidColorBrush x:Key="WindowBorderBrush" Color="#FFffffff" />
<SolidColorBrush
x:Key="DividerBorderBrush"
Opacity="0.0837"
Color="#FFFFFFFF" />
<SolidColorBrush x:Key="PrimaryForegroundBrush" Color="#FFffffff" />
<SolidColorBrush x:Key="SecondaryForegroundBrush" Color="#FF1aebff" />
</ResourceDictionary>

View File

@@ -1,26 +0,0 @@
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=System.Runtime">
<!-- Metadata -->
<system:String x:Key="Theme.Name">HighContrast.Accent5</system:String>
<system:String x:Key="Theme.Origin">PowerToysRun</system:String>
<system:String x:Key="Theme.DisplayName">Accent5 (HighContrast)</system:String>
<system:String x:Key="Theme.BaseColorScheme">HighContrast</system:String>
<system:String x:Key="Theme.ColorScheme">Accent5</system:String>
<Color x:Key="Theme.PrimaryAccentColor">White</Color>
<SolidColorBrush x:Key="SecondaryBackgroundBrush" Color="#FFEEEEEE" />
<SolidColorBrush
x:Key="PrimaryBackgroundBrush"
Opacity="0.25"
Color="#FFFFFFFF" />
<SolidColorBrush x:Key="WindowBorderBrush" Color="#FF000000" />
<SolidColorBrush
x:Key="DividerBorderBrush"
Opacity="0.0578"
Color="#FF000000" />
<SolidColorBrush x:Key="PrimaryForegroundBrush" Color="#FF000000" />
<SolidColorBrush x:Key="SecondaryForegroundBrush" Color="#FF37006e" />
</ResourceDictionary>

View File

@@ -1,35 +0,0 @@
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=System.Runtime">
<!-- Metadata -->
<system:String x:Key="Theme.Name">Light.Accent1</system:String>
<system:String x:Key="Theme.Origin">PowerToysRun</system:String>
<system:String x:Key="Theme.DisplayName">Accent1 (Light)</system:String>
<system:String x:Key="Theme.BaseColorScheme">Light</system:String>
<system:String x:Key="Theme.ColorScheme">Accent1</system:String>
<Color x:Key="Theme.PrimaryAccentColor">White</Color>
<SolidColorBrush x:Key="SecondaryBackgroundBrush" Color="#FFEEEEEE" />
<SolidColorBrush
x:Key="PrimaryBackgroundBrush"
Opacity="0.25"
Color="#FFFFFFFF" />
<SolidColorBrush
x:Key="WindowBorderBrush"
Opacity="0.4"
Color="#FF757575" />
<SolidColorBrush
x:Key="DividerBorderBrush"
Opacity="0.0578"
Color="#FF000000" />
<SolidColorBrush
x:Key="PrimaryForegroundBrush"
Opacity="0.8956"
Color="#FF000000" />
<SolidColorBrush
x:Key="SecondaryForegroundBrush"
Opacity="0.6189"
Color="#FF000000" />
</ResourceDictionary>