添加主题切换,未完成

This commit is contained in:
2025-07-12 12:55:46 +08:00
parent fabc63df44
commit bc23304ea0
6 changed files with 35 additions and 9 deletions

View File

@@ -49,6 +49,7 @@ public partial class App : Application
{
base.OnStartup(e);
ShutdownMode = ShutdownMode.OnExplicitShutdown;
ThemeHelper.InitializeTheme();
await Host.StartAsync();
try

View File

@@ -12,6 +12,7 @@ namespace PMSWPF.Config
public string UserId { get; set; } = "root";
public string Password { get; set; } = "Pgw15221236646";
public string Database { get; set; } = "pmswpf";
public string Theme { get; set; } = "跟随系统";
public bool EnableS7Service { get; set; } = true;
public bool EnableMqttService { get; set; } = true;
public bool EnableOpcUaService { get; set; } = true;

View File

@@ -25,6 +25,24 @@ public partial class SettingViewModel : ViewModelBase
_s7BackgroundService = s7BackgroundService;
_mqttBackgroundService = mqttBackgroundService;
_opcUaBackgroundService = opcUaBackgroundService;
Themes = new List<string> { "浅色", "深色", "跟随系统" };
}
public List<string> Themes { get; }
public string SelectedTheme
{
get => _connectionSettings.Theme;
set
{
if (_connectionSettings.Theme != value)
{
_connectionSettings.Theme = value;
OnPropertyChanged();
_connectionSettings.Save();
ThemeHelper.ApplyTheme(value);
}
}
}
public List<string> AvailableDbTypes { get; set; }
@@ -209,4 +227,4 @@ public partial class SettingViewModel : ViewModelBase
NotificationHelper.ShowError($"连接失败:{ex.Message}", ex);
}
}
}
}

View File

@@ -13,7 +13,6 @@
CloseButtonText="取消"
DefaultButton="Primary"
PrimaryButtonText="{Binding PrimaryButContent}"
Background="#fff"
d:DataContext="{d:DesignInstance vmd:DeviceDialogViewModel}"
mc:Ignorable="d">
<ui:ContentDialog.Resources>

View File

@@ -15,6 +15,12 @@
<ui:FontIcon Glyph="&#xE713;" />
</ui:SettingsExpander.HeaderIcon>
<ui:SettingsExpander.Items>
<ui:SettingsCard Header="主题切换"
Description="切换应用程序的主题">
<ComboBox Width="120"
ItemsSource="{Binding Themes}"
SelectedItem="{Binding SelectedTheme, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
</ui:SettingsCard>
<ui:SettingsCard Header="点击关闭按钮时最小化到通知栏"
Description="开启后,点击主窗口的关闭按钮会将程序最小化到系统通知栏,而不是直接退出。"
IsClickEnabled="True">

View File

@@ -30,7 +30,7 @@
<Style TargetType="TextBlock"
x:Key="VarTableLabelStyle">
<Setter Property="Foreground"
Value="#555" />
Value="{DynamicResource SecondaryTextBrush}" />
<Setter Property="FontSize"
Value="16" />
<Setter Property="VerticalAlignment"
@@ -165,7 +165,8 @@
CanUserSortColumns="True"
SelectionMode="Extended"
SelectedItem="{Binding SelectedVariableData}"
ItemsSource="{Binding VariableDataView}">
ItemsSource="{Binding VariableDataView}"
Style="{StaticResource DataGridBaseStyle}">
<DataGrid.ContextMenu>
<ContextMenu>
<MenuItem Header="添加变量"
@@ -230,9 +231,9 @@
<DataTrigger Binding="{Binding IsModified}"
Value="True">
<Setter Property="Background"
Value="Pink" />
Value="{DynamicResource SecondaryRegionBrush}" />
<Setter Property="Foreground"
Value="#000" />
Value="{DynamicResource PrimaryTextBrush}" />
<Setter Property="FontWeight"
Value="Bold" />
</DataTrigger>
@@ -240,14 +241,14 @@
<Trigger Property="IsMouseOver"
Value="True">
<Setter Property="Background"
Value="LightBlue" />
Value="{DynamicResource HoverBrush}" />
</Trigger>
<Trigger Property="IsSelected"
Value="True">
<Setter Property="Background"
Value="DodgerBlue" />
Value="{DynamicResource PrimaryBrush}" />
<Setter Property="Foreground"
Value="White" />
Value="{DynamicResource TextIconBrush}" />
</Trigger>
</Style.Triggers>
</Style>