【问题标题】:How to Change the background color and accent Color of winrt app using xaml Themeresource property如何使用 xaml Themeresource 属性更改 winrt 应用程序的背景颜色和强调颜色
【发布时间】:2017-05-18 07:56:50
【问题描述】:

我尝试了许多方法来实现或获取 Windows 8.1 的背景色和强调色以在 Winrt 应用程序中使用,但无法找到任何解决方案。我想知道除了使用 uwp 或使用任何第三方 dll 之外是否有任何解决方案,请告诉我。

【问题讨论】:

  • 也许this link会对你有所帮助。
  • 你在为周年更新编写代码吗?

标签: c# xaml windows-runtime winrt-xaml background-color


【解决方案1】:

WinRT 应用中的重点颜色值是以下值:

SystemAccentColor

你可以简单地使用它:

<Button Background={ThemeResource SystemAccentColor} />

我不确定您所引用的背景颜色是什么?您是指应用中使用的主题(浅色/深色)吗?

【讨论】:

    【解决方案2】:

    您可以在 App.xaml.cs 中尝试此代码:

     String brush="name of the brush you want to override";
     //example : for windows phone the name of the accent brush is PhoneAccentBrush
    
     (App.Current.Resources[brush] as SolidColorBrush).Color = Colors.Green;
    

    编辑:
    您可以使用此代码更改背景主题..

    App.Current.Resources["ApplicationPageBackgroundThemeBrush"‌​] as SolidColorBrush).Color = Colors.White;
    

    在页面的构造函数中使用它。至于重点画笔,没有可以直接应用的主题画笔。为此,您可以定义一个页面资源并将其分配给所有显示系统强调色的 UI 元素。

    【讨论】:

    • 实际上我正在处理win rt应用程序而不是手机。我还想获得可以从 Windows->settings->Personalise->Colors 设置的窗口的背景或强调颜色。如果从这里更改颜色,它应该会影响应用程序。
    • 请检查编辑部分!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-02
    • 1970-01-01
    • 2011-06-22
    • 2012-07-10
    相关资源
    最近更新 更多