Skip to content

Commit

Permalink
[QuickAccent]Move from ModernWPF to WpfUi (microsoft#29863)
Browse files Browse the repository at this point in the history
* Updating to WpfUI

* XAML styler

* Removing unused namespaces

* Updating ImageResizer watcher
  • Loading branch information
niels9001 authored Nov 16, 2023
1 parent 7e0f69f commit 7d9681e
Show file tree
Hide file tree
Showing 12 changed files with 91 additions and 292 deletions.
7 changes: 3 additions & 4 deletions src/modules/poweraccent/PowerAccent.UI/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
5 changes: 0 additions & 5 deletions src/modules/poweraccent/PowerAccent.UI/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
using System;
using System.Threading;
using System.Windows;
using Common.UI;
using ManagedCommon;
using PowerAccent.Core.Tools;

namespace PowerAccent.UI
{
Expand All @@ -18,7 +16,6 @@ public partial class App : Application, IDisposable
{
private static Mutex _mutex;
private bool _disposed;
private ThemeManager _themeManager;

protected override void OnStartup(StartupEventArgs e)
{
Expand All @@ -30,7 +27,6 @@ protected override void OnStartup(StartupEventArgs e)
Application.Current.Shutdown();
}

_themeManager = new ThemeManager(this);
base.OnStartup(e);
}

Expand All @@ -50,7 +46,6 @@ protected virtual void Dispose(bool disposing)
if (disposing)
{
_mutex?.Dispose();
_themeManager?.Dispose();
}

_disposed = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.Windows.CsWinRT" />
<PackageReference Include="ModernWpfUI" />
<PackageReference Include="WPF-UI" />
</ItemGroup>

<ItemGroup>
Expand Down
1 change: 0 additions & 1 deletion src/modules/poweraccent/PowerAccent.UI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using System.Windows;
using interop;
using ManagedCommon;
using PowerAccent.Core.Tools;

namespace PowerAccent.UI;

Expand Down
180 changes: 84 additions & 96 deletions src/modules/poweraccent/PowerAccent.UI/Selector.xaml
Original file line number Diff line number Diff line change
@@ -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>
Expand All @@ -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>
17 changes: 3 additions & 14 deletions src/modules/poweraccent/PowerAccent.UI/Selector.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -38,6 +38,7 @@ public Visibility CharacterNameVisibility
public Selector()
{
InitializeComponent();
Wpf.Ui.Appearance.SystemThemeWatcher.Watch(this);
Application.Current.MainWindow.ShowActivated = false;
Application.Current.MainWindow.Topmost = true;
}
Expand Down Expand Up @@ -67,7 +68,6 @@ private void PowerAccent_OnChangeDisplay(bool isActive, string[] chars)
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());
}
Expand All @@ -90,17 +90,6 @@ private void SetWindowPosition()
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();
Expand Down
32 changes: 0 additions & 32 deletions src/modules/poweraccent/PowerAccent.UI/Themes/Dark.xaml

This file was deleted.

26 changes: 0 additions & 26 deletions src/modules/poweraccent/PowerAccent.UI/Themes/HighContrast1.xaml

This file was deleted.

Loading

0 comments on commit 7d9681e

Please sign in to comment.