Skip to content

Commit

Permalink
feat: 优化 FluentDesign 实现
Browse files Browse the repository at this point in the history
  • Loading branch information
SlimeNull committed Jul 6, 2024
1 parent 7bdeb2e commit 72ae209
Show file tree
Hide file tree
Showing 18 changed files with 676 additions and 168 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0-windows;net6.0-windows;net48;net47;net46;net45</TargetFrameworks>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
<UseWPF>true</UseWPF>
<EnableWindowsTargeting>true</EnableWindowsTargeting>
<RootNamespace>EleCho.WpfSuite</RootNamespace>

<Version>0.0.1</Version>

<Authors>EleCho</Authors>
<Copyright>Copyright © 2024 EleCho</Copyright>
<PackageProjectUrl>https://github.com/OrgEleCho/EleCho.WpfSuite</PackageProjectUrl>
<PackageIcon>logo.png</PackageIcon>
<PackageTags>WPF;MVVM;Toolkit;Controls;Converters;BindingProxy</PackageTags>
<Description>WPF layout panels, controls, value converters, utilities suite</Description>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\EleCho.WpfSuite\EleCho.WpfSuite.csproj" />
</ItemGroup>

<ItemGroup>
<Folder Include="Controls\" />
<Folder Include="NewFolder\" />
</ItemGroup>

<ItemGroup>
<Page Update="Styles\PasswordBoxResources.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Update="Styles\TextBoxResources.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>

</Project>
13 changes: 10 additions & 3 deletions EleCho.WpfSuite.FluentDesign/EleCho.WpfSuite.FluentDesign.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,22 @@
</PropertyGroup>

<ItemGroup>
<Page Remove="FluentDesignResources.xaml" />
<ProjectReference Include="..\EleCho.WpfSuite\EleCho.WpfSuite.csproj" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\EleCho.WpfSuite\EleCho.WpfSuite.csproj" />
<Folder Include="Controls\" />
</ItemGroup>

<ItemGroup>
<Resource Include="FluentDesignResources.xaml" />
<Page Update="Styles\PasswordBoxResources.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Update="Styles\TextBoxResources.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>

</Project>
23 changes: 23 additions & 0 deletions EleCho.WpfSuite.FluentDesign/FluentDesignResourceKey.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.Reflection;
using System.Windows;

namespace EleCho.WpfSuite.FluentDesign
{
public class FluentDesignResourceKey : ResourceKey
{
private static readonly Assembly s_thisAssembly = Assembly.GetExecutingAssembly();

public override Assembly Assembly => s_thisAssembly;

public string Name { get; set; } = string.Empty;

public FluentDesignResourceKey(string name)
{
Name = name;
}

public FluentDesignResourceKey()
{
}
}
}
28 changes: 20 additions & 8 deletions EleCho.WpfSuite.FluentDesign/FluentDesignResources.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,32 @@

namespace EleCho.WpfSuite.FluentDesign
{
public class FluentDesignResourceKey : ResourceKey
{
private static readonly Assembly s_thisAssembly = Assembly.GetExecutingAssembly();

public override Assembly Assembly => s_thisAssembly;
}

public class FluentDesignResources : ResourceDictionary
{
FluentDesignThemeResources _themeResource;
ResourceDictionary _overviewResources;

public FluentDesignResources()
{
MergedDictionaries.Add(new ResourceDictionary() { Source = new Uri("pack://application:,,,/EleCho.WpfSuite.FluentDesign;component/FluentDesignResources.xaml") });
_themeResource = new FluentDesignThemeResources();
_overviewResources = new ResourceDictionary() { Source = new Uri("pack://application:,,,/EleCho.WpfSuite.FluentDesign;component/Styles/OverviewResources.xaml") };

MergedDictionaries.Add(_themeResource);
MergedDictionaries.Add(_overviewResources);
}


public bool IsDarkMode
{
get => _themeResource.IsDarkMode;
set => _themeResource.IsDarkMode = value;
}


// color keys
public static readonly FluentDesignResourceKey PrimaryColorKey = new FluentDesignResourceKey(nameof(PrimaryColorKey));

// brush keys
public static readonly FluentDesignResourceKey PrimaryBrushKey = new FluentDesignResourceKey(nameof(PrimaryBrushKey));
}
}
62 changes: 62 additions & 0 deletions EleCho.WpfSuite.FluentDesign/FluentDesignThemeResources.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using System;
using System.Windows;

namespace EleCho.WpfSuite.FluentDesign
{
public class FluentDesignThemeResources : ResourceDictionary
{
private readonly ResourceDictionary _lightThemeResources = new();
private readonly ResourceDictionary _darkThemeResources = new();

public FluentDesignThemeResources()
{
_lightThemeResources = new ResourceDictionary() { Source = new Uri("pack://application:,,,/EleCho.WpfSuite.FluentDesign;component/Themes/Light.xaml") };
_darkThemeResources = new ResourceDictionary() { Source = new Uri("pack://application:,,,/EleCho.WpfSuite.FluentDesign;component/Themes/Dark.xaml") };

MergedDictionaries.Add(_lightThemeResources);
}

public bool IsDarkMode
{
get => MergedDictionaries.Contains(_darkThemeResources);
set
{
MergedDictionaries.Clear();

if (value)
{
MergedDictionaries.Add(_darkThemeResources);
}
else
{
MergedDictionaries.Add(_lightThemeResources);
}
}
}

// color keys
public static readonly FluentDesignResourceKey TextColorKey = new FluentDesignResourceKey(nameof(TextColorKey));

public static readonly FluentDesignResourceKey ControlBackgroundColorKey = new FluentDesignResourceKey(nameof(ControlBackgroundColorKey));
public static readonly FluentDesignResourceKey ControlHoverBackgroundColorKey = new FluentDesignResourceKey(nameof(ControlHoverBackgroundColorKey));
public static readonly FluentDesignResourceKey ControlPressedBackgroundColorKey = new FluentDesignResourceKey(nameof(ControlPressedBackgroundColorKey));

public static readonly FluentDesignResourceKey TextBoxBackgroundColorKey = new FluentDesignResourceKey(nameof(TextBoxBackgroundColorKey));
public static readonly FluentDesignResourceKey TextBoxHoverBackgroundColorKey = new FluentDesignResourceKey(nameof(TextBoxHoverBackgroundColorKey));
public static readonly FluentDesignResourceKey TextBoxFocusedBackgroundColorKey = new FluentDesignResourceKey(nameof(TextBoxFocusedBackgroundColorKey));


// brush keys
public static readonly FluentDesignResourceKey TextBrushKey = new FluentDesignResourceKey(nameof(TextBrushKey));

public static readonly FluentDesignResourceKey ControlBackgroundBrushKey = new FluentDesignResourceKey(nameof(ControlBackgroundBrushKey));
public static readonly FluentDesignResourceKey ControlHoverBackgroundBrushKey = new FluentDesignResourceKey(nameof(ControlHoverBackgroundBrushKey));
public static readonly FluentDesignResourceKey ControlPressedBackgroundBrushKey = new FluentDesignResourceKey(nameof(ControlPressedBackgroundBrushKey));
public static readonly FluentDesignResourceKey ControlBorderBrushKey = new FluentDesignResourceKey(nameof(ControlBorderBrushKey));

public static readonly FluentDesignResourceKey TextBoxBackgroundBrushKey = new FluentDesignResourceKey(nameof(TextBoxBackgroundBrushKey));
public static readonly FluentDesignResourceKey TextBoxHoverBackgroundBrushKey = new FluentDesignResourceKey(nameof(TextBoxHoverBackgroundBrushKey));
public static readonly FluentDesignResourceKey TextBoxFocusedBackgroundBrushKey = new FluentDesignResourceKey(nameof(TextBoxFocusedBackgroundBrushKey));
public static readonly FluentDesignResourceKey TextBoxBorderBrushKey = new FluentDesignResourceKey(nameof(TextBoxBorderBrushKey));
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ws="clr-namespace:EleCho.WpfSuite;assembly=EleCho.WpfSuite"
xmlns:wsd="clr-namespace:EleCho.WpfSuite.FluentDesign"
xmlns:sys="clr-namespace:System;assembly=mscorlib">

<sys:String x:Key="WpfSuiteDesignName">SimpleDesign</sys:String>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/EleCho.WpfSuite.FluentDesign;component/Styles/TextBoxResources.xaml"/>
<ResourceDictionary Source="pack://application:,,,/EleCho.WpfSuite.FluentDesign;component/Styles/PasswordBoxResources.xaml"/>
</ResourceDictionary.MergedDictionaries>

<Color x:Key="PrimaryColor">#0067c0</Color>
<SolidColorBrush x:Key="PrimaryBrush" Color="{DynamicResource PrimaryColor}"/>
<Color x:Key="{x:Static wsd:FluentDesignResources.PrimaryColorKey}">#0067c0</Color>
<SolidColorBrush x:Key="{x:Static wsd:FluentDesignResources.PrimaryBrushKey}" Color="{DynamicResource ResourceKey={x:Static wsd:FluentDesignResources.PrimaryColorKey}}"/>

<LinearGradientBrush x:Key="ControlBorder" StartPoint="0,0" EndPoint="0,1">
<GradientStop Offset="0" Color="#18000000"/>
Expand All @@ -23,40 +27,16 @@
<LinearGradientBrush x:Key="FocusedTextBoxBorder" StartPoint="0,0" EndPoint="0,1">
<GradientStop Offset="0" Color="#18000000"/>
<GradientStop Offset=".9" Color="#18000000"/>
<GradientStop Offset="1" Color="{DynamicResource PrimaryColor}"/>
<GradientStop Offset="1" Color="{DynamicResource ResourceKey={x:Static wsd:FluentDesignResources.PrimaryColorKey}}"/>
</LinearGradientBrush>

<Style TargetType="{x:Type ws:TextBox}"
BasedOn="{StaticResource {x:Type ws:TextBox}}">
<Setter Property="CornerRadius" Value="4"/>
<Setter Property="Padding" Value="4 6"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="BorderBrush" Value="{StaticResource TextBoxBorder}"/>
<Setter Property="HoverBorderBrush" Value="{x:Null}"/>
<Setter Property="FocusedBorderBrush" Value="{StaticResource FocusedTextBoxBorder}"/>
<Setter Property="Background" Value="#EEFFFFFF"/>
<Setter Property="HoverBackground" Value="#88FFFFFF"/>
</Style>

<Style TargetType="{x:Type ws:PasswordBox}"
BasedOn="{StaticResource {x:Type ws:PasswordBox}}">
<Setter Property="CornerRadius" Value="4"/>
<Setter Property="Padding" Value="4 6"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="BorderBrush" Value="{StaticResource TextBoxBorder}"/>
<Setter Property="HoverBorderBrush" Value="{x:Null}"/>
<Setter Property="FocusedBorderBrush" Value="{StaticResource FocusedTextBoxBorder}"/>
<Setter Property="Background" Value="#EEFFFFFF"/>
<Setter Property="HoverBackground" Value="#88FFFFFF"/>
</Style>

<Style TargetType="{x:Type ws:Button}"
BasedOn="{StaticResource {x:Type ws:Button}}">
<Setter Property="CornerRadius" Value="4"/>
<Setter Property="Padding" Value="8 6"/>
<Setter Property="BorderBrush" Value="{StaticResource ControlBorder}"/>
<Setter Property="BorderBrush" Value="{DynamicResource {x:Static wsd:FluentDesignThemeResources.ControlBorderBrushKey}}"/>
<Setter Property="HoverBorderBrush" Value="{x:Null}"/>
<Setter Property="PressedBorderBrush" Value="{StaticResource ControlBorder}"/>
<Setter Property="PressedBorderBrush" Value="{x:Null}"/>
<Setter Property="Background" Value="#EEFFFFFF"/>
<Setter Property="HoverBackground" Value="#88FFFFFF"/>
<Setter Property="PressedBackground" Value="#44FFFFFF"/>
Expand All @@ -66,9 +46,9 @@
BasedOn="{StaticResource {x:Type ws:ToggleButton}}">
<Setter Property="CornerRadius" Value="4"/>
<Setter Property="Padding" Value="8 6"/>
<Setter Property="BorderBrush" Value="{StaticResource ControlBorder}"/>
<Setter Property="BorderBrush" Value="{DynamicResource {x:Static wsd:FluentDesignThemeResources.ControlBorderBrushKey}}"/>
<Setter Property="HoverBorderBrush" Value="{x:Null}"/>
<Setter Property="PressedBorderBrush" Value="{StaticResource ControlBorder}"/>
<Setter Property="PressedBorderBrush" Value="{x:Null}"/>
<Setter Property="Background" Value="#EEFFFFFF"/>
<Setter Property="HoverBackground" Value="#88FFFFFF"/>
<Setter Property="PressedBackground" Value="#44FFFFFF"/>
Expand All @@ -80,9 +60,9 @@
<Setter Property="CornerRadius" Value="4"/>
<Setter Property="PopupCornerRadius" Value="4"/>
<Setter Property="ClipToBounds" Value="True"/>
<Setter Property="BorderBrush" Value="{StaticResource ControlBorder}"/>
<Setter Property="HoverBorderBrush" Value="{StaticResource ControlBorder}"/>
<Setter Property="PressedBorderBrush" Value="{StaticResource ControlBorder}"/>
<Setter Property="BorderBrush" Value="{DynamicResource {x:Static wsd:FluentDesignThemeResources.ControlBorderBrushKey}}"/>
<Setter Property="HoverBorderBrush" Value="{x:Null}"/>
<Setter Property="PressedBorderBrush" Value="{x:Null}"/>
<Setter Property="Background" Value="#EEFFFFFF"/>
<Setter Property="HoverBackground" Value="#88FFFFFF"/>
<Setter Property="PressedBackground" Value="#44FFFFFF"/>
Expand Down
Loading

0 comments on commit 72ae209

Please sign in to comment.