locked
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

Answers

  •   Hi,

    myself figured out here is the answer.

    <Window
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
     x:Class="UntitledProject1.Window7"
     x:Name="Window"
     Title="Window7"
     Width="640" Height="480">
     <Window.Resources>
      <Style x:Key="ButtonStyleDemo" TargetType="{x:Type Button}">
       <Setter Property="Foreground" Value="#FF2F29FB"/>
      </Style>  
     </Window.Resources>
     <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" />
     </Grid>
    </Window>

    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:22 AM
    Thursday, December 11, 2008 3:18 AM