Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf-在运行时编辑资源_Wpf_Resources_Styles - Fatal编程技术网

Wpf-在运行时编辑资源

Wpf-在运行时编辑资源,wpf,resources,styles,Wpf,Resources,Styles,我有这个xaml: <Grid x:Name="root"> <Grid.Resources> <Style x:Key="btnStyle"> <Setter Property="Button.Background" Value="LightBlue"/> </Style> </Grid.Resources> <Button Style

我有这个xaml:

 <Grid x:Name="root">
    <Grid.Resources>
        <Style x:Key="btnStyle">
            <Setter Property="Button.Background" Value="LightBlue"/>
        </Style>
    </Grid.Resources>
    <Button Style="{DynamicResource btnStyle}"></Button>
</Grid>


我的问题是如何将btnStyle setter值从代码隐藏更改为红色?

这是对您问题的直接回答:

var style = (Style) this.root.findResource("btnStyle");
style.Setters.Item[0].Value = Brushes.Red;
但是你到底想做什么呢