gpt4 book ai didi

c# - Windows Phone 8 即使手机的主题发生变化,如何始终保持一个主题

转载 作者:太空狗 更新时间:2023-10-29 18:01:52 26 4
gpt4 key购买 nike

我的应用通常是为深色主题设计的,我正在使用StaticResources 所以如果用户将手机的主题更改为light应用变得不可读且无法使用。

我尝试手动更改每个元素的颜色并避免使用 StaticResources 和类似的东西:

Style="{StaticResource PhoneTextLargeStyle}"

StaticResources 用于字体和颜色。但这是一项艰苦的工作。

我如何才能全局更改我的应用程序的主题,认为手机主题是深色的? (这是一个 Windows Phone 8 应用程序)

最佳答案

更新:自 Windows Phone 8.1 发布以来,您可以在任何控件上设置 RequestedTheme 属性,甚至可以在应用级别覆盖用户在设置

强制使用 Light 主题的示例:

在代码中,在 App 类的构造函数中:

/// <summary>
/// Provides application-specific behavior to supplement the default Application class.
/// </summary>
public sealed partial class App : Application
{
private TransitionCollection transitions;

/// <summary>
/// Initializes the singleton application object. This is the first line of authored code
/// executed, and as such is the logical equivalent of main() or WinMain().
/// </summary>
public App()
{
this.RequestedTheme = ApplicationTheme.Light;

this.InitializeComponent();
this.Suspending += this.OnSuspending;
}
}

或者 在 XAML 中:

<Application
x:Class="App26.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
RequestedTheme="Light"
xmlns:local="using:App26">
</Application>

对于旧的 Windows Phone 8 应用程序模型:

当然,设计指南中建议使用主题资源,以确保您的应用适用于任何主题和强调色。

但是如果你真的想强制使用深色主题,这里是 Rudy Huyn 在他的博客上提供的解决方案:http://www.rudyhuyn.com/blog/2013/01/18/forcer-un-theme-sous-windows-phone-8/

想法是在您的 App 类中添加一个方法,该方法将使用深色主题的颜色覆盖所有系统画笔:

private void DarkTheme()
{
((SolidColorBrush)Resources["PhoneRadioCheckBoxCheckBrush"]).Color = ((SolidColorBrush)Resources["PhoneRadioCheckBoxBorderBrush"]).Color = ((SolidColorBrush)Resources["PhoneForegroundBrush"]).Color = Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF);
((SolidColorBrush)Resources["PhoneBackgroundBrush"]).Color = Color.FromArgb(0xFF, 0x00, 0x00, 0x00);
((SolidColorBrush)Resources["PhoneContrastForegroundBrush"]).Color = Color.FromArgb(0xFF, 0x00, 0x00, 0x00);
((SolidColorBrush)Resources["PhoneContrastBackgroundBrush"]).Color = Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF);
((SolidColorBrush)Resources["PhoneDisabledBrush"]).Color = Color.FromArgb(0x66, 0xFF, 0xFF, 0xFF);
((SolidColorBrush)Resources["PhoneProgressBarBackgroundBrush"]).Color = Color.FromArgb(0x19, 0xFF, 0xFF, 0xFF);
((SolidColorBrush)Resources["PhoneTextCaretBrush"]).Color = Color.FromArgb(0xFF, 0x00, 0x00, 0x00);
((SolidColorBrush)Resources["PhoneTextBoxBrush"]).Color = Color.FromArgb(0xBF, 0xFF, 0xFF, 0xFF);
((SolidColorBrush)Resources["PhoneTextBoxForegroundBrush"]).Color = Color.FromArgb(0xFF, 0x00, 0x00, 0x00);
((SolidColorBrush)Resources["PhoneTextBoxEditBackgroundBrush"]).Color = Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF);
((SolidColorBrush)Resources["PhoneTextBoxReadOnlyBrush"]).Color = Color.FromArgb(0x77, 0x00, 0x00, 0x00);
((SolidColorBrush)Resources["PhoneSubtleBrush"]).Color = Color.FromArgb(0x99, 0xFF, 0xFF, 0xFF);
((SolidColorBrush)Resources["PhoneTextBoxSelectionForegroundBrush"]).Color = Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF);
((SolidColorBrush)Resources["PhoneButtonBasePressedForegroundBrush"]).Color = Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF);
((SolidColorBrush)Resources["PhoneTextHighContrastBrush"]).Color = Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF);
((SolidColorBrush)Resources["PhoneTextMidContrastBrush"]).Color = Color.FromArgb(0x99, 0xFF, 0xFF, 0xFF);
((SolidColorBrush)Resources["PhoneTextLowContrastBrush"]).Color = Color.FromArgb(0x73, 0xFF, 0xFF, 0xFF);
((SolidColorBrush)Resources["PhoneSemitransparentBrush"]).Color = Color.FromArgb(0xAA, 0x00, 0x00, 0x00);
((SolidColorBrush)Resources["PhoneChromeBrush"]).Color = Color.FromArgb(0xFF, 0x1F, 0x1F, 0x1F);

((SolidColorBrush)Resources["PhoneInactiveBrush"]).Color = Color.FromArgb(0x33, 0xFF, 0xFF, 0xFF);
((SolidColorBrush)Resources["PhoneInverseInactiveBrush"]).Color = Color.FromArgb(0xFF, 0xCC, 0xCC, 0xCC);
((SolidColorBrush)Resources["PhoneInverseBackgroundBrush"]).Color = Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF);
((SolidColorBrush)Resources["PhoneBorderBrush"]).Color = Color.FromArgb(0xBF, 0xFF, 0xFF, 0xFF);
}

然后,在 App 构造函数中,检查是否启用了 Light 主题,如果是,则覆盖主题:

if ((Visibility) Resources["PhoneLightThemeVisibility"] == Visibility.Visible)
{
DarkTheme();
}

关于c# - Windows Phone 8 即使手机的主题发生变化,如何始终保持一个主题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17582998/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com