提交 1798018e 编写于 作者: Richard__Hu's avatar Richard__Hu

新增主题颜色设置,可设置浅色,暗色,已经其他色调。

上级 0eec231a
......@@ -164,6 +164,10 @@ using HslCommunication.Profinet;
![](https://github.com/dathlin/C-S-/raw/master/软件系统客户端Wpf/screenshots/client2.png)
###### 主窗口的暗色主题
![](https://github.com/dathlin/C-S-/raw/master/软件系统客户端Wpf/screenshots/client3.png)
###### 其他功能等待添加
<br />
......
......@@ -8,7 +8,13 @@
xmlns:y="clr-namespace:ClientsLibrary;assembly=ClientsLibrary"
mc:Ignorable="d"
Title="MainWindow" Height="550" Width="825" WindowState="Maximized" Activated="Window_Activated" Closing="Window_Closing" ContentRendered="Window_ContentRendered" Initialized="Window_Initialized"
Loaded="Window_Loaded">
Loaded="Window_Loaded"
TextElement.Foreground="{DynamicResource MaterialDesignBody}"
TextElement.FontWeight="Regular"
TextElement.FontSize="13"
TextOptions.TextFormattingMode="Ideal"
TextOptions.TextRenderingMode="Auto"
Background="{DynamicResource MaterialDesignPaper}">
<Window.Resources>
<ResourceDictionary>
......@@ -20,6 +26,8 @@
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.RadioButton.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.TextBlock.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.ToggleButton.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Shadows.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.ToggleButton.xaml" />
</ResourceDictionary.MergedDictionaries>
<Style TargetType="TextBlock" BasedOn="{StaticResource MaterialDesignCaptionTextBlock}" x:Key="Caption">
<Setter Property="Opacity" Value=".68"></Setter>
......@@ -126,7 +134,7 @@
</Menu>
<!--底部状态栏以及公告-->
<Grid DockPanel.Dock="Bottom" Background="WhiteSmoke">
<Grid DockPanel.Dock="Bottom">
<Grid Margin="2">
<Grid>
<Grid.ColumnDefinitions>
......@@ -140,8 +148,8 @@
<TextBlock x:Name="TextBlock_Version">1.0.0</TextBlock>
<TextBlock Margin="20,0,0,0">客户端状态:</TextBlock>
<TextBlock x:Name="TextBlock_ClientStatus">正在连接服务器...</TextBlock>
<TextBlock Margin="20,0,0,0" Foreground="Blue">温馨提示:</TextBlock>
<TextBlock x:Name="TextBlock_Information" Foreground="Blue"></TextBlock>
<TextBlock Margin="20,0,0,0" Foreground="DodgerBlue">温馨提示:</TextBlock>
<TextBlock x:Name="TextBlock_Information" Foreground="DodgerBlue"></TextBlock>
</StackPanel>
<StackPanel Grid.Column="1" Orientation="Horizontal">
......@@ -156,7 +164,7 @@
</Grid>
<Grid Width="100" DockPanel.Dock="Left">
<Border BorderThickness="0,1,1,1" BorderBrush="LightGray" Padding="5">
<Border BorderThickness="0,1,1,1" BorderBrush="DarkGray" Padding="5">
<StackPanel>
<TextBlock>随便放点什么东西</TextBlock>
<Button Style="{StaticResource MaterialDesignRaisedLightButton}" Grid.Column="1" Width="60" VerticalAlignment="Center"
......
......@@ -667,7 +667,7 @@ namespace 软件系统客户端Wpf
UIControl_Home = new UserHome();
all_main_render.Add(UIControl_Home);
UIControl_Palette = new UserPaletteSelector();
UIControl_Palette = new UserPaletteSelector() { DataContext = new PaletteSelectorViewModel() };
all_main_render.Add(UIControl_Palette);
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
namespace 软件系统客户端Wpf.Views
{
/// <summary>
/// No WPF project is complete without it's own version of this.
/// </summary>
public class AnotherCommandImplementation : ICommand
{
private readonly Action<object> _execute;
private readonly Func<object, bool> _canExecute;
public AnotherCommandImplementation(Action<object> execute) : this(execute, null)
{
}
public AnotherCommandImplementation(Action<object> execute, Func<object, bool> canExecute)
{
if (execute == null) throw new ArgumentNullException(nameof(execute));
_execute = execute;
_canExecute = canExecute ?? (x => true);
}
public bool CanExecute(object parameter)
{
return _canExecute(parameter);
}
public void Execute(object parameter)
{
_execute(parameter);
}
public event EventHandler CanExecuteChanged
{
add
{
CommandManager.RequerySuggested += value;
}
remove
{
CommandManager.RequerySuggested -= value;
}
}
public void Refresh()
{
CommandManager.InvalidateRequerySuggested();
}
}
}
using MaterialDesignColors;
using MaterialDesignThemes.Wpf;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
namespace 软件系统客户端Wpf.Views
{
public class PaletteSelectorViewModel
{
public PaletteSelectorViewModel()
{
Swatches = new SwatchesProvider().Swatches;
}
public ICommand ToggleBaseCommand { get; } = new AnotherCommandImplementation(o => ApplyBase((bool)o));
private static void ApplyBase(bool isDark)
{
new PaletteHelper().SetLightDark(isDark);
}
public IEnumerable<Swatch> Swatches { get; }
public ICommand ApplyPrimaryCommand { get; } = new AnotherCommandImplementation(o => ApplyPrimary((Swatch)o));
private static void ApplyPrimary(Swatch swatch)
{
new PaletteHelper().ReplacePrimaryColor(swatch);
}
public ICommand ApplyAccentCommand { get; } = new AnotherCommandImplementation(o => ApplyAccent((Swatch)o));
private static void ApplyAccent(Swatch swatch)
{
new PaletteHelper().ReplaceAccentColor(swatch);
}
}
}
......@@ -9,6 +9,9 @@
mc:Ignorable="d"
d:DesignHeight="700" d:DesignWidth="400">
<UserControl.Resources>
<Style x:Key="MaterialDesignFloatingHintTextBox" BasedOn="{StaticResource MaterialDesignFloatingHintTextBox}" TargetType="{x:Type TextBox}">
<Setter Property="FontSize" Value="24" />
</Style>
<Style TargetType="Button" BasedOn="{StaticResource MaterialDesignFlatButton}">
<Setter Property="Margin" Value="0" />
<Setter Property="CommandParameter" Value="{Binding}" />
......@@ -82,7 +85,8 @@
<wpf:Card DockPanel.Dock="Top" Margin="2">
<DockPanel>
<local:Palette DockPanel.Dock="Left" Width="200" />
<TextBlock Margin="16" TextWrapping="Wrap" VerticalAlignment="Center">This is your current palette. Configure your initial palette in App.xaml, but palettes can be changed at runtime.</TextBlock>
<TextBlock Margin="16" TextWrapping="Wrap" VerticalAlignment="Center">这是你当前的主题配色,可以在app.xaml中进行配置和初始化,
也可以在运行的时候进行更改。</TextBlock>
</DockPanel>
</wpf:Card>
<Grid Margin="0 16 0 0">
......@@ -91,9 +95,9 @@
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal" Margin="8">
<TextBlock VerticalAlignment="Center">Light</TextBlock>
<TextBlock VerticalAlignment="Center">浅色主题</TextBlock>
<ToggleButton Margin="8 0 16 0" Command="{Binding ToggleBaseCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Self}, Path=IsChecked}" />
<TextBlock VerticalAlignment="Center">Dark</TextBlock>
<TextBlock VerticalAlignment="Center">暗色主题</TextBlock>
</StackPanel>
<ScrollViewer Grid.Row="1" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled" Margin="0 12 0 0">
<ItemsControl ItemsSource="{Binding Swatches, Mode=OneTime}">
......
......@@ -73,9 +73,11 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="Views\AnotherCommandImplementation.cs" />
<Compile Include="Views\Palette.xaml.cs">
<DependentUpon>Palette.xaml</DependentUpon>
</Compile>
<Compile Include="Views\PaletteSelectorViewModel.cs" />
<Compile Include="Views\UserChat.xaml.cs">
<DependentUpon>UserChat.xaml</DependentUpon>
</Compile>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册