如何使用 ConfigurationFile 设置样式值? [英] How can i set value of style with ConfigurationFile?

查看:17
本文介绍了如何使用 ConfigurationFile 设置样式值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为我的解决方案的所有标签设置属性.所以我在 app.xaml 中编写样式,但我想为用户创造可能性他们可以改变其风格的价值.帮我用配置文件设置值value ← configurationmanager.appsetting.get(" ... ").

I want set property for all the label of my solution . so i write style in app.xaml but i want create the possibility for users that they can change value of its style. help me to set the value with configuration file value ← configurationmanager.appsetting.get(" ... ").

推荐答案

您可以将样式中的属性值绑定到 应用程序设置.假设应用程序设置 ButtonBackground 类型为 SolidColorBrush,app.config 将包含:

Instead of using ConfigurationManager you could bind property values in a style to application settings. Assume an application setting ButtonBackground of type SolidColorBrush, the app.config would contain this:

<applicationSettings>
    <TestApp.Properties.Settings>
        <setting name="ButtonBackground" serializeAs="String">
            <value>#FF008000</value>
        </setting>
    </TestApp.Properties.Settings>
</applicationSettings>

在 App.xaml 中,您可以将样式属性绑定到应用程序设置,如下所示:

In App.xaml you could bind a style property to an application setting like this:

<Application x:Class="TestApp.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:p="clr-namespace:TestApp.Properties"
             StartupUri="MainWindow.xaml">
    <Application.Resources>
        <Style TargetType="Button">
            <Setter Property="Background" Value="{Binding Source={x:Static p:Settings.Default}, Path=ButtonBackground}"/>
        </Style>
    </Application.Resources>
</Application>

这篇关于如何使用 ConfigurationFile 设置样式值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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