Wpf-在运行时编辑资源
我有这个xaml: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
<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;
但是你到底想做什么呢