[UWP] [Xaml] Windows中的自动强调色如何工作? [英] [UWP][Xaml] How does auto accent color works in Windows?

查看:107
本文介绍了[UWP] [Xaml] Windows中的自动强调色如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在尝试创建一个应用,用户可以为应用选择自定义背景,我希望应用颜色根据所选背景而变化,就像Windows中的自动强调色一样。

有没有人知道如何实现这一点?

I am trying to make an app where the user can select custom background for the app, and i want the app colors change depending on the selected background, just like auto accent color in Windows.
does anyone has any idea on how to achieve that?

推荐答案

<

嗯,我不确定我是否误解了你的问题。如果您想将背景颜色更改为客户想要的颜色,可能的方法是您可以将控件中需要使用的所有颜色定义为App.Xaml中的颜色资源。然后,你需要在后面的代码中更改颜色资源

Well, I'm not sure if I misunderstand your question. If you want to change the background color to what the customer wants, a possible way is that you could defined all the colors you need to use in the controls as color resources in the App.Xaml. Then you could change the color resource once you need to change them in the code behind.

我做了一个关于此的简单代码演示:

I made a simple code demo about this:

App.Xaml:

  <Application.Resources>
        <!--it is a brush that I used in mainpage-->
        <SolidColorBrush x:Key="TestThemeColor" Color="Red"> </SolidColorBrush>
    </Application.Resources>

MainPage.Xaml

MainPage.Xaml

 <Grid Background="{ThemeResource TestThemeColor}">
        <Button Click="Button_Click" Content="Click"/>
    </Grid>

MainPage.Xaml.cs

MainPage.Xaml.cs

 public MainPage()
        {
            this.InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            //change the resource and then the mainpage will change to blue
            (Application.Current.Resources["TestThemeColor"] as SolidColorBrush).Color = Windows.UI.Colors.Blue;
        }




祝你好运,

Roy


这篇关于[UWP] [Xaml] Windows中的自动强调色如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆