简体   繁体   English

更改Windows Phone 8.1中所有对象的颜色

[英]Change color of all object in Windows Phone 8.1

I have some TextBlock, Grid, TextBox, etc in my pages . 我的页面中有一些TextBlock,Grid,TextBox等。 I want to change their colors in all page because I have a setting for change color in my app. 我想在所有页面上更改其颜色,因为我在我的应用中设置了更改颜色的设置。 How can I change color all of them in all pages with code? 如何用代码更改所有页面中所有颜色?
I search a little for data Binding But I couldn't understand something. 我搜索了一些数据绑定,但我听不懂。 (I am amateur) (我是业余爱好者)
please help me? 请帮我?

Assign a SolidColorBrush key in your resource dictionary. 在资源字典中分配一个SolidColorBrush键。

<SolidColorBrush x:Key="DynamicBrush" Color="White"/>

Initially give the color as what you need and bind it to controls in all pages. 最初根据需要提供颜色,然后将其绑定到所有页面的控件中。 When user tends to change the color then you can change the key value in your resource dictionary which will be reflected in pages where all you have used that key. 当用户倾向于更改颜色时,可以在资源字典中更改键值,该键值将反映在所有使用该键的页面中。

XAML XAML

<Button Content="change" x:Name="BtnChange" Click="BtnChange_Click"/>

C# C#

private void BtnChange_Click(object sender, RoutedEventArgs e)
    {
        App.Current.Resources["DynamicBrush"] = new SolidColorBrush(Colors.Red);
        this.Foreground = App.Current.Resources["DynamicBrush"] as SolidColorBrush;
    }

This will help you. 这将为您提供帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM