Skip to content

Commit

Permalink
将 UI 改成 Windows 11 的风格
Browse files Browse the repository at this point in the history
  • Loading branch information
walterlv committed Feb 16, 2022
1 parent 045b894 commit 91745f2
Show file tree
Hide file tree
Showing 35 changed files with 997 additions and 1,369 deletions.
22 changes: 15 additions & 7 deletions WindowDebugger/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,23 @@
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>

<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Themes/Core.xaml" />
<ResourceDictionary Source="/Themes/FDS/Window.xaml" />
<ResourceDictionary Source="/Themes/FDS/Button.xaml" />
<ResourceDictionary Source="/Themes/FDS/ScrollBar.xaml" />
<ResourceDictionary Source="/Themes/FDS/ScrollViewer.xaml" />
<ResourceDictionary Source="/Themes/FDS/ListBox.xaml" />
<ResourceDictionary Source="/Themes/FDS/TabControl.xaml" />
<ResourceDictionary Source="pack://application:,,,/WPFUI;component/Styles/Theme/Dark.xaml" />
<ResourceDictionary Source="pack://application:,,,/WPFUI;component/Styles/WPFUI.xaml" />
<ResourceDictionary Source="/Themes/Windows11/WPFUIFix.xaml" />
</ResourceDictionary.MergedDictionaries>

<Style TargetType="{x:Type ScrollViewer}" BasedOn="{StaticResource UiScrollViewer}" />

<!-- Colors depending on the theme should be changed by the Manager -->
<Color x:Key="SystemAccentColor">#1570a6</Color>

<!-- While the name remains Light to stay with the official nomenclature, it's made dark in Dark Theme -->
<Color x:Key="SystemAccentColorLight1">#3396cf</Color>
<Color x:Key="SystemAccentColorLight2">#80b9ee</Color>
<Color x:Key="SystemAccentColorLight3">#add8ff</Color>

</ResourceDictionary>
</Application.Resources>
</Application>
7 changes: 7 additions & 0 deletions WindowDebugger/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,19 @@
using System.Threading.Tasks;
using System.Windows;

using WPFUI.Theme;

namespace WindowDebugger
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
Watcher.Start(true, true);
}
}
}
165 changes: 40 additions & 125 deletions WindowDebugger/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,137 +4,52 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WindowDebugger"
xmlns:views="clr-namespace:WindowDebugger.Views"
xmlns:viewmodels="clr-namespace:WindowDebugger.ViewModels"
xmlns:effects="clr-namespace:Walterlv.Windows.Effects;assembly=Walterlv.Themes.FluentDesign"
xmlns:converters="clr-namespace:WindowDebugger.Converters"
mc:Ignorable="d" DataContext="{x:Static viewmodels:ViewModel.Instance}"
Title="WindowDebugger" Height="640" Width="960" MinHeight="550" MinWidth="800" Loaded="Window_Loaded"
Style="{StaticResource Style.Window}"
Icon="/icon.ico">
<Window.Resources>
<converters:IntPtrToInt32Converter x:Key="IntPtrToInt32Converter" />
<Style x:Key="Style.ListBoxItem" TargetType="ListBoxItem">
<Setter Property="Foreground" Value="{StaticResource Brush.Theme.Foreground}" />
<Setter Property="Background" Value="Transparent" />
<Setter Property="Height" Value="40" />
<Setter Property="Padding" Value="0" />
<Setter Property="Margin" Value="0" />
<Setter Property="FocusVisualStyle" Value="{x:Null}" />
<Setter Property="TextOptions.TextHintingMode" Value="Animated" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<Grid effects:TiltEffect2D.IsEnabled="True">
<Border Name="BackBorder" BorderThickness="0 0 0 1" Visibility="Collapsed">
<Border.Background>
<effects:RevealBorderBrush Color="{StaticResource Color.Theme.Light1}" Radius="200" />
</Border.Background>
</Border>
<Border x:Name="ContentBorder" Background="{TemplateBinding Background}" BorderThickness="0 0 0 1">
<Border.BorderBrush>
<effects:RevealBorderBrush />
</Border.BorderBrush>
<ContentPresenter />
</Border>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="BackBorder" Property="Visibility" Value="Visible" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Foreground" Value="{StaticResource Brush.Foreground}" />
<Setter Property="Background" Value="{StaticResource Brush.Background}" />
</Trigger>
</Style.Triggers>
</Style>
<DataTemplate x:Key="DataTemplate.WindowItem" DataType="viewmodels:WindowItem">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="72" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Opacity="0.5" Margin="10 4"
FontFamily="Consolas" FontSize="12"
Text="{Binding WindowHandle, Converter={StaticResource IntPtrToInt32Converter}, StringFormat={}{0:X8}, Mode=OneWay}" />
<TextBlock Grid.Column="1" Margin="0 4" Text="{Binding Text, Mode=OneWay}"
TextWrapping="WrapWithOverflow" TextTrimming="CharacterEllipsis" />
</Grid>
</DataTemplate>
</Window.Resources>
xmlns:pages="clr-namespace:WindowDebugger.Views.Pages"
xmlns:win11="clr-namespace:WPFUI.Controls;assembly=WPFUI"
mc:Ignorable="d"
Width="1200" Height="800" MinWidth="800" MinHeight="550"
Title="WindowDebugger"
Style="{StaticResource UiWindow}" Background="Transparent" Icon="/icon.ico"
SourceInitialized="Window_SourceInitialized"
ContentRendered="Window_ContentRendered">

<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" MinWidth="250"/>
<ColumnDefinition Width="4*"/>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>

<!--窗口列表-->
<Grid Grid.Column="0" Background="#1570A6">
<Grid.RowDefinitions>
<RowDefinition Height="32"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<!-- 标题栏 -->
<win11:TitleBar Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" Panel.ZIndex="1"
Title="{Binding Title, RelativeSource={RelativeSource AncestorType=Window}}"
Icon="{Binding Icon, RelativeSource={RelativeSource AncestorType=Window}}" />

<!--标题栏-->
<Grid Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" Background="{StaticResource Brush.Theme}">
</Grid>
<!-- 导航栏 -->
<win11:NavigationStore x:Name="RootNavigation" Grid.Row="1" Grid.Column="0"
Margin="6,0,6,0" Frame="{Binding ElementName=RootFrame}">
<win11:NavigationStore.Items>
<win11:NavigationItem Content="Windows" Icon="PictureInPicture24" Tag="windows" Type="{x:Type pages:WindowsPage}" />
</win11:NavigationStore.Items>
<win11:NavigationStore.Footer>
<win11:NavigationItem Content="About" Icon="Info24" Tag="about" Type="{x:Type pages:AboutPage}" />
</win11:NavigationStore.Footer>
</win11:NavigationStore>

<TextBox Grid.Row="1" Grid.ColumnSpan="2"
Margin="8 8 0 0" Padding="8 4" FontSize="14"
Text="{Binding SearchText, UpdateSourceTrigger=PropertyChanged}"
VerticalContentAlignment="Center"
Foreground="{StaticResource Brush.Theme.Foreground}"
Background="{StaticResource Brush.Theme.Dark1}">
<TextBox.BorderBrush>
<effects:RevealBorderBrush />
</TextBox.BorderBrush>
</TextBox>
<Button Grid.Row="1" Grid.Column="2"
Padding="0" Width="32" Height="32" Margin="0 8 8 0"
Content="&#xE895;" FontFamily="Segoe MDL2 Assets"
Click="RefreshWindowList"/>
<ListBox Grid.Row="2" Grid.ColumnSpan="3" x:Name="WindowList"
ItemsSource="{Binding Windows, Mode=OneWay}"
SelectedItem="{Binding SelectedWindow, Mode=TwoWay}"
BorderThickness="0" Background="Transparent" Padding="0"
ItemContainerStyle="{StaticResource Style.ListBoxItem}"
ItemTemplate="{StaticResource DataTemplate.WindowItem}"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
VirtualizingPanel.ScrollUnit="Pixel" />
</Grid>
<!-- 内容栏 -->
<Border Grid.Row="1" Grid.Column="1"
Background="{DynamicResource ControlFillColorDefaultBrush}"
CornerRadius="8,0,0,0">
<Grid>
<Frame x:Name="RootFrame" />
<win11:Breadcrumb Margin="18,18,0,0" HorizontalAlignment="Left" VerticalAlignment="Top"
FontSize="24"
Navigation="{Binding ElementName=RootNavigation}" />
</Grid>
</Border>

<Grid Grid.Row="1" Grid.Column="1">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TabControl Margin="8 16 12 8"
DataContext="{Binding SelectedWindow}"
DataContextChanged="TabControl_DataContextChanged"
ItemContainerStyle="{StaticResource {x:Type TabItem}}">
<views:WindowInfoTab Header="Info"/>
<views:WindowStylesTab Header="Styles"/>
<views:WindowStylesExTab Header="StyleExes"/>
<views:ClassStylesTab Header="ClassStyles"/>
<views:OperationsTab Header="Operations"/>
<views:DWMTab Header="DWM"/>
<views:OthersTab Header="Others"/>
</TabControl>
<Button Grid.Row="1" Content="Refresh Current" MaxWidth="200"
Click="RefreshCurrent"
Margin="16,0,10,16" Padding="24 0" Height="40">
</Button>
</Grid>
</Grid>
</Window>
60 changes: 8 additions & 52 deletions WindowDebugger/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.ComponentModel;
using System;
using System.ComponentModel;
using System.Linq;
using System.Windows;
using System.Windows.Interop;
Expand All @@ -12,66 +13,21 @@ namespace WindowDebugger
/// </summary>
public partial class MainWindow : Window
{
ViewModel Model => ViewModel.Instance;
public MainWindow()
{
WPFUI.Background.Manager.Apply(this);
InitializeComponent();
}

private void Window_Loaded(object sender, RoutedEventArgs e)
private void Window_SourceInitialized(object sender, EventArgs e)
{
_ = UpdateHelper.CheckUpdate();
RefreshWindowList(null, null);
var hwnd = new WindowInteropHelper(this).Handle;
WPFUI.Background.Manager.Apply(WPFUI.Background.BackgroundType.Mica, hwnd);
}

private void RefreshWindowList(object sender, RoutedEventArgs e)
private void Window_ContentRendered(object sender, EventArgs e)
{
var selectedNew = Model.SelectedWindow;
var selected = default(WindowItem);

Model.RefreshWindowList();

if (selectedNew != null)
{
selected = Model.Windows.FirstOrDefault(x => x.WindowHandle == selectedNew.WindowHandle);
}

Model.SelectedWindow = selected ?? Model.Windows.FirstOrDefault(x => x.WindowHandle == new WindowInteropHelper(this).Handle);
if (Model.SelectedWindow != null)
{
WindowList.ScrollIntoView(WindowList.Items[WindowList.Items.Count - 1]);
WindowList.ScrollIntoView(Model.SelectedWindow);
}
}

private void RefreshCurrent(object sender, RoutedEventArgs e)
{
Model.SelectedWindow?.RefreshItem();
Model.SelectedWindow?.RefreshScreenShot();
}

private void TabControl_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
{
if (e.OldValue is WindowItem olditem)
{
olditem.PropertyChanged -= WindowItem_PropertyChanged;
}
if (e.NewValue is WindowItem newitem)
{
newitem.PropertyChanged += WindowItem_PropertyChanged;
}
}

private void WindowItem_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (sender is WindowItem item && e.PropertyName == nameof(WindowItem.ErrorString))
{
if (item.ErrorString != null)
{
MessageBox.Show(this, item.ErrorString);
item.ErrorString = null;
}
}
RootNavigation.Navigate("windows", false);
}
}
}
33 changes: 0 additions & 33 deletions WindowDebugger/Themes/Core.xaml

This file was deleted.

Loading

0 comments on commit 91745f2

Please sign in to comment.