Use EnvironmentInfo as Resource


   
       

<StackPanel xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:s="clr-namespace:System;assembly=mscorlib">
    <TextBlock>
        <Label Content="Operating System Version: " />  
        <Label Content="{x:Static s:Environment.OSVersion}" />
        <LineBreak />
        <Label Content=".NET Version: " />
        <Label Content="{x:Static s:Environment.Version}" />
        <LineBreak />
        <Label Content="Machine Name: " />
        <Label Content="{x:Static s:Environment.MachineName}" />
        <LineBreak />
        <Label Content="User Name: " />
        <Label Content="{x:Static s:Environment.UserName}" />
        <LineBreak />
        <Label Content="User Domain Name: " />
        <Label Content="{x:Static s:Environment.UserDomainName}" />
        <LineBreak />
        <Label Content="System Directory: " />
        <Label Content="{x:Static s:Environment.SystemDirectory}" />
        <LineBreak />
        <Label Content="Current Directory: " />
        <Label Content="{x:Static s:Environment.CurrentDirectory}" />
        <LineBreak />
        <Label Content="Command Line: " />
        <Label Content="{x:Static s:Environment.CommandLine}" />
    </TextBlock>
</StackPanel>

   
    
    
    
    
    
    
     


Font Size Resources


   
       

<StackPanel xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:s="clr-namespace:System;assembly=mscorlib">

    <StackPanel.Resources>
        <s:Double x:Key="fontsizeLarge">18</s:Double>
        <s:Double x:Key="fontsizeSmall">14</s:Double>
    </StackPanel.Resources>

    <Button HorizontalAlignment="Center" 
            VerticalAlignment="Center" 
            Margin="24">
        <Button.FontSize>
            <StaticResource ResourceKey="fontsizeLarge" />
        </Button.FontSize>
        Button with large FontSize
    </Button>

    <Button HorizontalAlignment="Center"
            VerticalAlignment="Center"
            Margin="24"
            FontSize="{StaticResource fontsizeSmall}" >
        Button with small FontSize
    </Button>

</StackPanel>

   
    
    
    
    
    
    
     


Add a logical resource to the window's resource dictionary


   
    

<Window x:Class="WpfApplication1.MainWindow"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  Title="FunWithResources" Height="207" Width="612" WindowStartupLocation="CenterScreen">
  <Window.Resources>
    <Style x:Key ="MyFunkyStyle">
      <Setter Property ="Control.FontSize" Value ="20"/>
      <Setter Property ="Control.Background">
        <Setter.Value>
          <LinearGradientBrush StartPoint="0,0" EndPoint="1,1">
            <GradientStop Color="Green" Offset="0" />
            <GradientStop Color="Yellow" Offset="0.25" />
          </LinearGradientBrush>
        </Setter.Value>
      </Setter>
    </Style>
    <Style x:Key ="NewFunkyStyle" BasedOn = "{StaticResource MyFunkyStyle}">
      <Setter Property = "Button.Foreground" Value = "Blue"/>
      <Setter Property = "Button.RenderTransform">
        <Setter.Value>
          <RotateTransform Angle = "20"/>
        </Setter.Value>
      </Setter>
    </Style>

  </Window.Resources>
  <StackPanel>
    <Image Name ="companyLogo" Source ="c:image.gif"/>
    <Button Name="btnClickMe" Style ="{StaticResource NewFunkyStyle}" Content = "Click Me"/>
    <Button Name="btnClickMeToo" Style ="{StaticResource NewFunkyStyle}" Content = "Me Too"/>
    <TextBox Name="txtAndMe" Style ="{StaticResource MyFunkyStyle}" Text = "And me!"/>
  </StackPanel>
</Window>

   
    
    
    
     


Define Double value as resource


   
       

<Window x:Class="Styles.ReuseFontWithResources"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="ReuseFontWithResources" Height="368" Width="378"
    xmlns:s="clr-namespace:System;assembly=mscorlib"
    >
  <Window.Resources>    
    <FontFamily x:Key="ButtonFontFamily">Times New Roman</FontFamily>
    <s:Double x:Key="ButtonFontSize">18</s:Double>
    <FontWeight x:Key="ButtonFontWeight">Bold</FontWeight>    
  </Window.Resources>
  <StackPanel Margin="5">
    <Button Padding="5" Margin="5"
            FontFamily="{StaticResource ButtonFontFamily}"
            FontWeight="{StaticResource ButtonFontWeight}"
            FontSize="{StaticResource ButtonFontSize}" 
              >A Customized Button</Button>
  </StackPanel>
</Window>

   
    
    
    
    
    
    
     


Reuse Font With Resources


   
       
<Window x:Class="Styles.ReuseFontWithResources"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="ReuseFontWithResources" Height="368" Width="378"
    xmlns:s="clr-namespace:System;assembly=mscorlib"
    >
  <Window.Resources>    
    <FontFamily x:Key="ButtonFontFamily">Times New Roman</FontFamily>
    <s:Double x:Key="ButtonFontSize">18</s:Double>
    <FontWeight x:Key="ButtonFontWeight">Bold</FontWeight>    
  </Window.Resources>
  <StackPanel Margin="5">
    <Button Padding="5" Margin="5"
            FontFamily="{StaticResource ButtonFontFamily}"
            FontWeight="{StaticResource ButtonFontWeight}"
            FontSize="{StaticResource ButtonFontSize}" 
              >A Customized Button</Button>
  </StackPanel>
</Window>

   
    
    
    
    
    
    
     


Event Triggers as Resource


   
       

<Window x:Class="Styles.EventTriggers"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="EventTriggers" Height="300" Width="300">
  <Window.Resources>
    <Style x:Key="BigFontButton">
      <Style.Setters>
        <Setter Property="Control.FontSize" Value="18" />
        <Setter Property="Control.FontWeight" Value="Bold" />
      </Style.Setters>
      
      <Style.Triggers>
        <EventTrigger RoutedEvent="Mouse.MouseEnter">
          <EventTrigger.Actions>
            <BeginStoryboard>
              <Storyboard>
                <DoubleAnimation Duration="0:0:0.2" Storyboard.TargetProperty="FontSize"
                  To="22"  />
              </Storyboard>
            </BeginStoryboard>
          </EventTrigger.Actions>
        </EventTrigger>
        <EventTrigger RoutedEvent="Mouse.MouseLeave">
          <EventTrigger.Actions>
            <BeginStoryboard>
              <Storyboard>
                <DoubleAnimation
                  Duration="0:0:1"
                  Storyboard.TargetProperty="FontSize"  />
              </Storyboard>
            </BeginStoryboard>
          </EventTrigger.Actions>
        </EventTrigger>

      </Style.Triggers>
    </Style>
    
  </Window.Resources>

  <StackPanel Margin="5">
    <Button Padding="5" Margin="5" Style="{StaticResource BigFontButton}">A Customized Button</Button>
  </StackPanel>
</Window>

   
    
    
    
    
    
    
     


Button style as Window resource


   
       

<Window x:Class="Styles.AutomaticStyles"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="AutomaticStyles" Height="300" Width="300"
    >
  <Window.Resources>
    <Style TargetType="Button">
      <Setter Property="FontFamily" Value="Times New Roman" />
      <Setter Property="FontSize" Value="18" />
      <Setter Property="FontWeight" Value="Bold" />
    </Style>
  </Window.Resources>

  <StackPanel Margin="5">
    <Button Padding="5" Margin="5">Customized Button</Button>
    <Button Padding="5" Margin="5" Style="{x:Null}">A Normal Button</Button>
    <Button Padding="5" Margin="5">Another Customized Button</Button>
  </StackPanel>
</Window>