Wpf 如何使用ConfigurationFile设置样式值?

Wpf 如何使用ConfigurationFile设置样式值?,wpf,Wpf,我希望为解决方案的所有标签设置属性。 因此,我在app.xaml中编写样式,但我希望为用户创造可能性 它们可以改变其样式的值。 帮助我使用配置文件设置值 价值← configurationmanager.appsetting.get(“…”)。好的。。。一旦使用,就无法更改样式。但是你可以采取一个简单的解决办法 嗯。。。一旦使用,就无法更改样式。但是你可以采取一个简单的解决办法 不使用ConfigurationManager,您可以将样式中的属性值绑定到。假设应用程序设置ButtonBackgr

我希望为解决方案的所有标签设置属性。 因此,我在app.xaml中编写样式,但我希望为用户创造可能性 它们可以改变其样式的值。 帮助我使用配置文件设置值
价值← configurationmanager.appsetting.get(“…”)。

好的。。。一旦使用,就无法更改样式。但是你可以采取一个简单的解决办法

嗯。。。一旦使用,就无法更改样式。但是你可以采取一个简单的解决办法

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

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

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

<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>

您可以使用样式将属性值绑定到,而不是使用ConfigurationManager。假设应用程序设置
ButtonBackground
类型为
SolidColorBrush
,则app.config将包含以下内容:

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

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

<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>