[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"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:PowerAccent"
xmlns:ui="http://schemas.modernwpf.com/2019"
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
StartupUri="Selector.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ui:ThemeResources />
<ui:XamlControlsResources />
<ui:ThemesDictionary Theme="Dark" />
<ui:ControlsDictionary />
</ResourceDictionary.MergedDictionaries>
<!-- Other app resources here -->
</ResourceDictionary>

View File

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

View File

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

View File

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

View File

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

View File

@@ -5,13 +5,13 @@
using System;
using System.ComponentModel;
using System.Windows;
using PowerAccent.Core.Services;
using Wpf.Ui.Controls;
using Point = PowerAccent.Core.Point;
using Size = PowerAccent.Core.Size;
namespace PowerAccent.UI;
public partial class Selector : Window, IDisposable, INotifyPropertyChanged
public partial class Selector : FluentWindow, IDisposable, INotifyPropertyChanged
{
private readonly Core.PowerAccent _powerAccent = new();
@@ -38,6 +38,7 @@ public partial class Selector : Window, IDisposable, INotifyPropertyChanged
public Selector()
{
InitializeComponent();
Wpf.Ui.Appearance.SystemThemeWatcher.Watch(this);
Application.Current.MainWindow.ShowActivated = false;
Application.Current.MainWindow.Topmost = true;
}
@@ -67,7 +68,6 @@ public partial class Selector : Window, IDisposable, INotifyPropertyChanged
characters.SelectedIndex = _selectedIndex;
this.UpdateLayout(); // Required for filling the actual width/height before positioning.
SetWindowPosition();
SetWindowAlignment();
Show();
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;
}
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)
{
_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>