2010-12-01 72 views
0

我有這樣的XAML:WPF - 編輯資源在運行時

<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二傳手值從代碼更改爲紅色的背後?

回答

1

這是直接回答你的問題:

var style = (Style) this.root.findResource("btnStyle"); 
style.Setters.Item[0].Value = Brushes.Red; 

但什麼是你要完成的是什麼呢?