Change the Style/Templete in runtime RRS feed

  • Question

  • Hi,

    I want to change the Style/Templete of the button using code in runtime
    any examples ?

    Prasad - www.beautifulmind.blog.co.in
    Friday, December 5, 2008 4:05 AM


  •   Hi,

    myself figured out here is the answer.

     Width="640" Height="480">
      <Style x:Key="ButtonStyleDemo" TargetType="{x:Type Button}">
       <Setter Property="Foreground" Value="#FF2F29FB"/>
     <Grid x:Name="LayoutRoot">
      <Button HorizontalAlignment="Left" Margin="98,0,0,126" VerticalAlignment="Bottom" Width="146" Height="59" Content="Button" x:Name="Button1" Click="Button1_Click" />

    in .cs file

    private void Button1_Click(object sender, RoutedEventArgs e)


    Button1.Style = this.Resources["ButtonStyleDemo"] as Style;


    Prasad - www.beautifulmind.blog.co.in
    • Marked as answer by prasad22 Monday, December 15, 2008 11:25 AM
    Thursday, December 11, 2008 3:17 AM