22 August 2009

Styles in Wpf


  1. Open Visual Studio 2008
  2. New WPF windows application
  3. Open window1.xaml file
  4. Write below given code above <Grid>


<Window.Resources>


<Style x:Key="mystyle" TargetType="Button">


<Setter Property="Background" Value="Orange"/>


<Setter Property="FontStyle" Value="Italic"/>


<Setter Property="Padding" Value="8,4"/>


<Setter Property="Margin" Value="4"/>


</Style>


</Window.Resources>

  1. Write below code between <Grid>… …</Grid>


<StackPanel Orientation="Horizontal" HorizontalAlignment="Center"
VerticalAlignment="Center">


<Button Style="{StaticResource mystyle}" Content="Vijay"/>


<Button Style="{StaticResource mystyle}" Content="Raju"/>


<Button Style="{StaticResource mystyle}" Content="Mygo"/>


</StackPanel>

  1. Execute the program..