Paints a rectangle with a grid pattern with VisualBrush


   
     
<Window x:Class="Workspace.DockExample"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Workspace" Width="640" Height="480">
      <Rectangle Width="50" Height="50" Grid.Row="1" Grid.Column="1">
        <Rectangle.Fill>
          <VisualBrush Viewport="0,0,1,0.25" TileMode="Tile" Stretch="Uniform">
            <VisualBrush.Visual>
              <StackPanel Background="White">
                <TextBlock FontSize="10pt" Margin="1">Hello, World!</TextBlock>
              </StackPanel>
            </VisualBrush.Visual>
            <VisualBrush.RelativeTransform>
              <RotateTransform Angle="-45" CenterX="0.5" CenterY="0.5" />
            </VisualBrush.RelativeTransform>
          </VisualBrush>
        </Rectangle.Fill>
      </Rectangle>
</Window>

   
    
    
    
    
     


A rectangle with curved corners


   
     
<Window x:Class="WpfApplication1.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="WpfApplication1" Height="352" Width="334" WindowStartupLocation="CenterScreen">
    <StackPanel>
    <Rectangle RadiusX ="20" RadiusY ="50" Fill ="DarkBlue" Width ="150" Height ="50"/>
    </StackPanel>
</Window>

   
    
    
    
    
     


RadioButton checked event handler


   
 
<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" SizeToContent="Height" Width="300">
    <Grid Name="grid">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition/>
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>
        <Border Grid.Column="0" BorderBrush="Gray" BorderThickness="1" />
        <Border Grid.Column="1" BorderBrush="Gray" BorderThickness="1" />
        <StackPanel Grid.Column="0" HorizontalAlignment="Center" Margin="5" Name="spLeftContainer">
            <TextBlock FontSize="16" Text="Radio Group 1" />
            <RadioButton Content="Radio Button 1A" GroupName="Group1" IsChecked="True" Margin="5" Name="rbnOneA" />
            <RadioButton Content="Radio Button 1B" GroupName="Group1" Margin="5" Name="rbnOneB" />
            <RadioButton Content="Radio Button 1C" GroupName="Group1" Margin="5" Name="rbnOneC" />
            <Separator/>
            <TextBlock FontSize="16" Text="Radio Group 2" />
            <RadioButton Checked="RadioButton_Checked" GroupName="Group2" Content="Radio Button 2A" IsChecked="True" 
                         Margin="5" Name="rbnTwoA" />
            <RadioButton Checked="RadioButton_Checked" GroupName="Group2" Content="Radio Button 2B" Margin="5" Name="rbnTwoB"/>
            <RadioButton Checked="RadioButton_Checked" GroupName="Group2" Content="Radio Button 2C" Margin="5" Name="rbnTwoC"/>
        </StackPanel>
        <StackPanel Grid.Column="1" HorizontalAlignment="Center" Margin="5" Name="spRightContainer">
            <TextBlock FontSize="16" Text="Radio Group 1" />
            <RadioButton Content="Radio Button 1D" GroupName="Group1" Margin="5" Name="rbnOneD" />
            <RadioButton Content="Radio Button 1E" GroupName="Group1" Margin="5" Name="rbnOneE" />
        </StackPanel>
        <Button Content="Show Group1 Selection" Grid.ColumnSpan="2" Grid.Row="1" HorizontalAlignment="Center" 
                Margin="10" MaxHeight="25" Click="Button_Click" />
    </Grid>
</Window>

//File:Window.xaml.cs
using System;
using System.Linq;
using System.Windows;
using System.Windows.Controls;

namespace WpfApplication1
{
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            RadioButton radioButton = null;
            radioButton = GetCheckedRadioButton(spLeftContainer.Children, "Group1");
            if (radioButton == null)
            {
                radioButton = GetCheckedRadioButton(spRightContainer.Children, "Group1");
            }
            MessageBox.Show(radioButton.Content + " checked.", Title);
        }
        private RadioButton GetCheckedRadioButton(UIElementCollection children, String groupName)
        {
            return children.OfType<RadioButton>().FirstOrDefault( rb => rb.IsChecked == true &amp;&amp; rb.GroupName == groupName);
        }
        private void RadioButton_Checked(object sender, RoutedEventArgs e)
        {
            if (!this.IsInitialized) return;
            RadioButton radioButton = e.OriginalSource as RadioButton;

            if (radioButton != null)
            {
                MessageBox.Show(radioButton.Content + " checked.", Title);
            }
        }
    }
}

   
     


Use RadioButton to control TextBox alignment


   
 

<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="300" Width="300">
    <StackPanel>
        <TextBox AcceptsReturn="True" Height="100" IsReadOnly="True" 
                 Name="textBox1" TextAlignment="Left" TextWrapping="Wrap" 
                 VerticalScrollBarVisibility="Auto">
            Default starting text.
        </TextBox>
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition/>
                <ColumnDefinition/>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>
            <RadioButton Checked="AlignmentChecked" Grid.Column="0" 
                         HorizontalAlignment="Center" IsChecked="True"
                         Margin="5" Name="leftAlignRadioButton">
                Left</RadioButton>
            <RadioButton Checked="AlignmentChecked" Grid.Column="1" 
                         HorizontalAlignment="Center" Margin="5"
                         Name="centerAlignRadioButton">
                Center</RadioButton>
            <RadioButton Checked="AlignmentChecked" Grid.Column="2" 
                         HorizontalAlignment="Center" Margin="5"
                         Name="rightAlignRadioButton">
                Right</RadioButton>
        </Grid>
    </StackPanel>
</Window>
//File:Window.xaml.cs
using System.Windows;
using System.Windows.Controls;

namespace WpfApplication1
{
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
        }
        private void AlignmentChecked(object sender, RoutedEventArgs e)
        {
            RadioButton button = e.OriginalSource as RadioButton;

            if (e.OriginalSource == leftAlignRadioButton)
            {
                textBox1.TextAlignment = TextAlignment.Left;
            }
            else if (e.OriginalSource == centerAlignRadioButton)
            {
                textBox1.TextAlignment = TextAlignment.Center;
            }
            else if (e.OriginalSource == rightAlignRadioButton)
            {
                textBox1.TextAlignment = TextAlignment.Right;
            }

            textBox1.Focus();
        }
    }
}

   
     


Use RadioButton to control TextBox alignment


   
 

<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="300" Width="300">
    <StackPanel>
        <TextBox AcceptsReturn="True" Height="100" IsReadOnly="True" 
                 Name="textBox1" TextAlignment="Left" TextWrapping="Wrap" 
                 VerticalScrollBarVisibility="Auto">
            Default starting text.
        </TextBox>
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition/>
                <ColumnDefinition/>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>
            <RadioButton Checked="AlignmentChecked" Grid.Column="0" 
                         HorizontalAlignment="Center" IsChecked="True"
                         Margin="5" Name="leftAlignRadioButton">
                Left</RadioButton>
            <RadioButton Checked="AlignmentChecked" Grid.Column="1" 
                         HorizontalAlignment="Center" Margin="5"
                         Name="centerAlignRadioButton">
                Center</RadioButton>
            <RadioButton Checked="AlignmentChecked" Grid.Column="2" 
                         HorizontalAlignment="Center" Margin="5"
                         Name="rightAlignRadioButton">
                Right</RadioButton>
        </Grid>
    </StackPanel>
</Window>
//File:Window.xaml.cs
using System.Windows;
using System.Windows.Controls;

namespace WpfApplication1
{
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
        }
        private void AlignmentChecked(object sender, RoutedEventArgs e)
        {
            RadioButton button = e.OriginalSource as RadioButton;

            if (e.OriginalSource == leftAlignRadioButton)
            {
                textBox1.TextAlignment = TextAlignment.Left;
            }
            else if (e.OriginalSource == centerAlignRadioButton)
            {
                textBox1.TextAlignment = TextAlignment.Center;
            }
            else if (e.OriginalSource == rightAlignRadioButton)
            {
                textBox1.TextAlignment = TextAlignment.Right;
            }

            textBox1.Focus();
        }
    }
}

   
     


RadioButton click event


   
 
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Class="ProgBar.Window1"
    Title ="ProgressBar"
    Width="500">

  <Grid>
    <StackPanel Grid.Column="0" Grid.Row="2">
      <Label>Choose number of ProgressBar iterations.</Label>
      <RadioButton Content="One" Click="MakeOne"/>
      <RadioButton Content="Three" Click="MakeThree"/>
      <RadioButton Content="Five" Click="MakeFive"/>
      <RadioButton Content="Forever" Click="MakeForever"/>
      <RadioButton Content="Indeterminate" Click="MakeIndeterminate"/>
    </StackPanel>
  </Grid>
</Window>
//File:Window.xaml.cs
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;



namespace ProgBar
{

    public partial class Window1 : Window
    {
        
        private void MakeOne(object sender, RoutedEventArgs e)
        {
           Console.WriteLine("E");
          } 

         private void MakeThree(object sender, RoutedEventArgs e)
         {
           Console.WriteLine("D");
         }
        
        private void MakeFive(object sender, RoutedEventArgs e)
        {
            Console.WriteLine("c");
         }
 
         private void MakeForever(object sender, RoutedEventArgs e)
         {
           Console.WriteLine("B");
          
         }

         private void MakeIndeterminate(object sender, RoutedEventArgs e)
         {
             Console.WriteLine("A");
         }

     }
}

   
     


Image RadioButton


   
 
<Window x:Class="ControlDemos.RadioButton"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="ControlDemos" Height="600" Width="500">
    <Grid>
      <StackPanel>
        <RadioButton Click="HandleSelection" Name="r1">
          <StackPanel Orientation="Horizontal">
            <Image Source="c:image.jpg" ></Image>
            <TextBlock FontSize="24" Height="35" Width="150">A</TextBlock>
          </StackPanel>
        </RadioButton>
        <RadioButton Click="HandleSelection" Name="r2">
          <StackPanel Orientation="Horizontal">
            <Image Source="c:image.jpg" ></Image>
            <TextBlock FontSize="24" Height="35" Width="150">B</TextBlock>
          </StackPanel>
        </RadioButton>
        <RadioButton Click="HandleSelection" Name="r3">
          <StackPanel Orientation="Horizontal">
            <Image Source="c:image.jpg" Height="200" Width="256"></Image>
            <TextBlock FontSize="24" Height="35" Width="150">C</TextBlock>
          </StackPanel>
        </RadioButton>
      </StackPanel>
  <Menu Name="menu1" />
</Grid>
</Window>
//File:Window.xaml.cs
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace ControlDemos
{
    public partial class RadioButton : Window
    {

        public RadioButton()
        {
            InitializeComponent();
        }
        public void HandleSelection(Object sender, RoutedEventArgs e)
        {
            System.Windows.Controls.RadioButton b = (sender as System.Windows.Controls.RadioButton);
            StackPanel d = (StackPanel)b.Content;
            TextBlock t = (TextBlock)d.Children[1];
            Console.WriteLine(t.Text);
        }
    }
}