CheckBox checked event listener


   
  


<Window x:Class="LayoutPanels.LocalizableText"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Layout" Height="365" Width="380" MinWidth="350" MinHeight="150">
  <Grid>
    <StackPanel>
      <Button Name="cmdPrev" Margin="10,10,10,3">Prev</Button>
      <Button Name="cmdNext" Margin="10,3,10,3">Next</Button>      
      <CheckBox Name="chkLongText" Margin="10,10,10,10" Checked="chkLongText_Checked" Unchecked="chkLongText_Unchecked">Show Long Text</CheckBox>
    </StackPanel>    
    <TextBox  Margin="0,10,10,10" TextWrapping="WrapWithOverflow">
     This behavior makes localization much easier.</TextBox>
    <Button Grid.Row="1" Grid.Column="0" Name="cmdClose" Margin="10,3,10,10">Close</Button>
  </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 LayoutPanels
{

    public partial class LocalizableText : Window
    {

        public LocalizableText()
        {
            InitializeComponent();
        }

        private void chkLongText_Checked(object sender, RoutedEventArgs e)
        {            
            cmdPrev.Content = " <- Go to the Previous Window ";
            cmdNext.Content = " Go to the Next Window -> ";
        }

        private void chkLongText_Unchecked(object sender, RoutedEventArgs e)
        {
            cmdPrev.Content = "Prev";
            cmdNext.Content = "Next";
        }
    }
}

   
    
     


CheckBox Style


   
    
<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="220" Width="300">
    <Window.Resources>
        <Style x:Key="BaseControlStyle" 
               TargetType="{x:Type Control}">
            <Setter Property="FontFamily" Value="Tahoma" />
            <Setter Property="FontSize" Value="24pt"/>
            <Setter Property="Margin" Value="4" />
        </Style>

        <Style TargetType="{x:Type Button}" 
               BasedOn="{StaticResource BaseControlStyle}">
            <Setter Property="FontWeight" Value="Bold" />
        </Style>

        <Style TargetType="{x:Type CheckBox}" 
               BasedOn="{StaticResource BaseControlStyle}">
        </Style>
        <Style TargetType="{x:Type TextBox}" 
               BasedOn="{StaticResource BaseControlStyle}">
        </Style>

    </Window.Resources>

    <Grid>
        <StackPanel>
            <CheckBox>CheckBox</CheckBox>
            <TextBox>TextBox</TextBox>
            <Button>Button</Button>
            <Button FontWeight="Light">Button with overridden style</Button>
            <TextBlock>TextBlock</TextBlock>
            <ComboBox>ComboBox</ComboBox>
        </StackPanel>
    </Grid>
</Window>

   
    
    
    
     


Customized CheckBox


   
    
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Page.Resources>
        <ControlTemplate x:Key="switch" TargetType="{x:Type CheckBox}">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <Canvas Background="LightGray">
                    <Line Name="lineOff"
                              StrokeThickness="8" Stroke="Black"
                              X1="48" Y1="40" X2="20" Y2="16"
                              StrokeStartLineCap="Round"
                              StrokeEndLineCap="Round"  />
                    <Line Name="lineOn"
                              StrokeThickness="8" Stroke="Black"
                              X1="48" Y1="40" X2="76" Y2="16"
                              StrokeStartLineCap="Round"
                              StrokeEndLineCap="Round" 
                              Visibility="Hidden"  />
                </Canvas>
                <ContentPresenter Grid.Row="1" 
                                  Content="{TemplateBinding Content}"
                                  HorizontalAlignment="Center" />
            </Grid>
            <ControlTemplate.Triggers>
                <Trigger Property="IsChecked" Value="True">
                    <Setter TargetName="lineOff" Property="Visibility"
                            Value="Hidden" />
                    <Setter TargetName="lineOn" Property="Visibility"
                            Value="Visible" />
                </Trigger>
            </ControlTemplate.Triggers>
        </ControlTemplate>
    </Page.Resources>

    <CheckBox Template="{StaticResource switch}"
              Content="Customized CheckBox"
              HorizontalAlignment="Center"
              VerticalAlignment="Center" />
</Page>

   
    
    
    
     


Add CheckBox to StackPanel


   
    

<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  HorizontalAlignment="Center" VerticalAlignment="Center">
    <StackPanel Background="#ECE9D8">
      <TextBlock Margin="3">Look for:</TextBlock>
      <ComboBox  Margin="3"/>
      <TextBlock Margin="3">Filtered by:</TextBlock>
      <ComboBox  Margin="3"/>
      <Button    Margin="3,5">Search</Button>
      <CheckBox  Margin="3">Search in titles only</CheckBox>
      <CheckBox  Margin="3">Match related words</CheckBox>
      <CheckBox  Margin="3">Search in previous results</CheckBox>
      <CheckBox  Margin="3">Highlight search hits (in topics)</CheckBox>
    </StackPanel>

</Window>

   
    
    
    
     


A CheckBox with a skew transformation


   
    

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

    <Button Content ="Click Me!" Grid.Row="0" Grid.Column="1" Width="95" Height="40">
      <Button.RenderTransform>
        <SkewTransform AngleX ="20" AngleY ="20"/>
      </Button.RenderTransform>
    </Button>

  </Grid>

</Window>

   
    
    
    
     


Three-State CheckBox


   
    

<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>
      <!-- CheckBox -->
      <HeaderedItemsControl Header="CheckBox">
        <CheckBox Margin="8">Normal</CheckBox>
        <CheckBox Margin="8" IsChecked="true">Checked</CheckBox>
        <CheckBox Margin="8" IsThreeState="true" IsChecked="{x:Null}">Indeterminate</CheckBox>
      </HeaderedItemsControl>
   
    </WrapPanel>
  </ScrollViewer>
</Window>

   
    
    
    
     


Get position on a Canvas with Canvas.GetLeft


   
  

<Canvas xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Class="Thumb_wcp.Pane1">
  <Canvas Width="100" Height="100" Name="myCanvasStretch">
    <TextBox Name="changes" 
         Width="{Binding ElementName=myCanvasStretch,Path=Width}"  
         Height="{Binding ElementName=myCanvasStretch,Path=Height}" 
         Text="Size: 100, 100"/>
    <Thumb Name="myThumb" Canvas.Left="80" Canvas.Top="80" Background="Blue" 
          Width="20" Height="20" DragDelta="onDragDelta"/>
  </Canvas>
</Canvas>

//File:Window.xaml.cs

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Documents;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Data;
using System.Windows.Media;

namespace Thumb_wcp
{
    public partial class Pane1 : Canvas
    {
        void onDragDelta(object sender, DragDeltaEventArgs e)
        {
            double yadjust = myCanvasStretch.Height + e.VerticalChange;
            double xadjust = myCanvasStretch.Width + e.HorizontalChange;
            if ((xadjust >= 0) &amp;&amp; (yadjust >= 0))
            {
                myCanvasStretch.Width = xadjust;
                myCanvasStretch.Height = yadjust;
                Canvas.SetLeft(myThumb, Canvas.GetLeft(myThumb) + e.HorizontalChange);
                Canvas.SetTop(myThumb, Canvas.GetTop(myThumb) + e.VerticalChange);
                Console.WriteLine(myCanvasStretch.Width);
                Console.WriteLine(myCanvasStretch.Height);
            }
        }

    }
}