ToolBar and Button, ToggleButton, ComboBox and Separator


   
     
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  Title="About WPF" SizeToContent="WidthAndHeight"
  Background="OrangeRed">
  
<Canvas>
  <ToolBar>
    <Button>
      <Image Source="c:image.gif"/>
    </Button>
    <Separator/>
    <ToggleButton>
      <Image Source="c:image.gif"/>
    </ToggleButton>
    <ToggleButton>
      <Image Source="c:image.gif"/>
    </ToggleButton>
    <ToggleButton>
      <Image Source="c:image.gif"/>
    </ToggleButton>
    <Separator/>
    <ToggleButton>
      <Image Source="c:image.gif"/>
    </ToggleButton>
    <ToggleButton>
      <Image Source="c:image.gif"/>
    </ToggleButton>
    <ToggleButton>
      <Image Source="c:image.gif"/>
    </ToggleButton>
    <Separator/>
    <Label>Zoom</Label>
    <ComboBox SelectedIndex="0">
      <ComboBoxItem>100%</ComboBoxItem>
      <ComboBoxItem>75%</ComboBoxItem>
      <ComboBoxItem>50%</ComboBoxItem>
      <ComboBoxItem>25%</ComboBoxItem>
    </ComboBox>
    <Separator/>
    <Button>
      <Image Source="c:image.gif"/>
    </Button>
    <Button>
      <Image Source="c:image.gif"/>
    </Button>
  </ToolBar>
</Canvas>
</Window>

   
    
    
    
    
     


ToolTip for Border


   
    
<Window x:Class="SimpleStyles.Window1"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  Title="SimpleStyles"
  Background="#F8F8F8">
  <ScrollViewer>
    <WrapPanel>
      <HeaderedItemsControl Header="ToolTip">
        <StackPanel>
          <Border Margin="8" Background="#EEE" Width="150" Height="50"  CornerRadius="2">
            <Border.ToolTip>
              This is a test tooltip!  Woohoo!
            </Border.ToolTip>
            <TextBlock Foreground="#AAA" VerticalAlignment="Center" 
               HorizontalAlignment="Center">(Hover Over Me)</TextBlock>
          </Border>
        </StackPanel>
      </HeaderedItemsControl>
   
    </WrapPanel>
  </ScrollViewer>
</Window>

   
    
    
    
     


Toolbar Trays


   
    
<Window x:Class="MenusAndToolbars.ToolbarTrays"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="ToolbarTrays" Height="300" Width="300"
    >
  <DockPanel>
    <ToolBarTray DockPanel.Dock="Top" >
      <ToolBar>
        <Button ToolBar.OverflowMode="Never">One</Button>
        <Button>Two</Button>
        <Button>Three</Button>
      </ToolBar>
      <ToolBar>
        <Button ToolBar.OverflowMode="Never">A</Button>
        <Button ToolBar.OverflowMode="Never">B</Button>
        <Button>C</Button>
      </ToolBar>      
      <ToolBar Band="1">
        <Button>Red</Button>
        <Button>Blue</Button>        
        <Button>Green</Button>
        <Button>Black</Button>
      </ToolBar>
    </ToolBarTray>    
    <!--<ToolBarTray DockPanel.Dock="Left" Orientation="Vertical">
      <ToolBar>
        <Button>One</Button>
        <Button>One</Button>
        <Button>One</Button>
      </ToolBar>
    </ToolBarTray>-->
    <TextBox></TextBox>
  </DockPanel>
</Window>

   
    
    
    
     


Basic Toolbar


   
    

<Window x:Class="MenusAndToolbars.BasicToolbar"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="BasicToolbar" Height="300" Width="400">
    <Grid>
      <Grid.RowDefinitions>
        <RowDefinition Height="Auto"></RowDefinition>
      </Grid.RowDefinitions>
      <ToolBar>
        <Separator></Separator>
        <Button>Open</Button>
        <Button>Save</Button>
        <Button>Close</Button>
        <Separator></Separator>
        <CheckBox FontWeight="Bold">Bold</CheckBox>
        <CheckBox FontStyle="Italic">Italic</CheckBox>
        <CheckBox>
          <TextBlock TextDecorations="Underline">Underline</TextBlock>
        </CheckBox>
        <Separator></Separator>        
        <ComboBox SelectedIndex="0">
          <ComboBoxItem>100%</ComboBoxItem>
          <ComboBoxItem>50%</ComboBoxItem>
          <ComboBoxItem>25%</ComboBoxItem>
        </ComboBox>
      </ToolBar>
    </Grid>
  
</Window>

   
    
    
    
     


ToolBarTray


   
    
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      HorizontalAlignment="Stretch" VerticalAlignment="Top">
    <ToolBarTray>
      <ToolBar>
        <Button>
          <Canvas Width="16" Height="16" SnapsToDevicePixels="True">
            <Polygon Stroke="Black" StrokeThickness="0.5" Points="2.5,1.5 9.5,1.5 12.5,4.5 12.5,15 2.5,15">
              <Polygon.Fill>
                <LinearGradientBrush StartPoint="1,1" EndPoint="0.2,0.7">
                  <GradientStop Offset="0" Color="#AAA" />
                  <GradientStop Offset="1" Color="White" />
                </LinearGradientBrush>
              </Polygon.Fill>
            </Polygon>
            <Polygon Stroke="Black" Fill="DarkGray" StrokeThickness="0.5" StrokeLineJoin="Bevel" Points="9.5,1.5 9.5,4.5 12.5,4.5" />
          </Canvas>
        </Button>
      </ToolBar>
      <ToolBar>
        <Button>Second toolbar</Button>
        <CheckBox IsChecked="True">Choice</CheckBox>
      </ToolBar>
    </ToolBarTray>
</Page>

   
    
    
    
     


Update the UI Asynchronously on a Timer


   
  

<Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="WPF" Height="100" Width="300">
    <StackPanel>
        <Button x:Name="button" Click="Button_Click">Start Timer</Button>
        <TextBlock x:Name="txtStatus">
        </TextBlock>
    </StackPanel>
</Window>

//File:Window.xaml.cs

using System;
using System.Windows;
using System.Windows.Threading;

namespace WpfApplication1
{
    public partial class Window1 : Window
    {
        private DispatcherTimer timer;
         
        public Window1()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if(timer == null || !timer.IsEnabled)
            {
                timer = new DispatcherTimer();

                timer.Interval = TimeSpan.FromMilliseconds(1000);
                timer.Tick += new EventHandler(timer_Tick);

                timer.Start();
                button.Content = "Stop Timer";
            }
            else
            {
                timer.Stop();
                button.Content = "Start Timer";
            }
        }

        private void timer_Tick(object sender, EventArgs e)
        {
            txtStatus.Text = DateTime.Now.Second.ToString();
        }
    }
}