C# 如何在Windows 10中使用系统应用程序模式(UWP、WPF)
我想在我的桌面应用程序中使用系统主题设置。我需要使用应用程序模式(亮或暗)。例如,当我们在Windows中使用黑暗模式,并在我的应用程序中单击“更改主题”按钮时,我的应用程序中的主题模式应将主题模式更改为Windows应用程序模式 我找到了一个解决方案,但该示例显示了如何在系统颜色设置中获取主题名称,而不是应用程序模式C# 如何在Windows 10中使用系统应用程序模式(UWP、WPF),c#,.net,wpf,uwp,C#,.net,Wpf,Uwp,我想在我的桌面应用程序中使用系统主题设置。我需要使用应用程序模式(亮或暗)。例如,当我们在Windows中使用黑暗模式,并在我的应用程序中单击“更改主题”按钮时,我的应用程序中的主题模式应将主题模式更改为Windows应用程序模式 我找到了一个解决方案,但该示例显示了如何在系统颜色设置中获取主题名称,而不是应用程序模式 public string GetTheme() { string RegistryKey = @"HKEY_CURRENT_USER\SOFTWARE\Microsof
public string GetTheme()
{
string RegistryKey = @"HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes";
string theme;
theme = (string)Registry.GetValue(RegistryKey, string.Empty, string.Empty);
theme = theme.Split('\\').Last().Split('.').First().ToString();
return theme;
}
对于uwp,您可以使用以下方法设置应用程序的它们
public static async Task SetRequestedThemeAsync(ElementTheme theme)
{
foreach (var view in CoreApplication.Views)
{
await view.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
if (Window.Current.Content is FrameworkElement frameworkElement)
{
frameworkElement.RequestedTheme = theme;
}
});
}
}
你在使用Winforms吗?WPF?还有别的吗?请确定正在使用的相关技术。uwp、wpf技术