Four-quadrant Cartesian coordinate system

image_pdfimage_print


   
      
<Grid xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Grid.Resources>
        <Style TargetType="{x:Type Canvas}">
            <Setter Property="Width" Value="100" />
            <Setter Property="Height" Value="100" />
            <Setter Property="HorizontalAlignment" Value="Center" />
            <Setter Property="VerticalAlignment" Value="Center" />
        </Style>

        <Style TargetType="{x:Type Path}">
            <Setter Property="Fill" Value="Red" />
            <Setter Property="Data">
                <Setter.Value>
                    <EllipseGeometry Center="0 0" RadiusX="5" RadiusY="5" />
                </Setter.Value>
            </Setter>
        </Style>
    </Grid.Resources>


    <Canvas Grid.Column="3">
        <Canvas.RenderTransform>
            <TransformGroup>
                <ScaleTransform ScaleY="-1" />
                <TranslateTransform X="50" Y="50" />
            </TransformGroup>
        </Canvas.RenderTransform>

        <Line X1="0" Y1="0" X2="50" Y2="50" Stroke="Black" />
        <Polyline Points="-50 -50 50 -50 50 50 -50 50 -50 -50" Stroke="Blue" />
        <Path />
    </Canvas>

</Grid>

   
    
    
    
    
    
     


Origin at lower left. Y increases going up

image_pdfimage_print


   
      
<Grid xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Grid.Resources>
        <Style TargetType="{x:Type Canvas}">
            <Setter Property="Width" Value="100" />
            <Setter Property="Height" Value="100" />
            <Setter Property="HorizontalAlignment" Value="Center" />
            <Setter Property="VerticalAlignment" Value="Center" />
        </Style>

        <Style TargetType="{x:Type Path}">
            <Setter Property="Fill" Value="Red" />
            <Setter Property="Data">
                <Setter.Value>
                    <EllipseGeometry Center="0 0" RadiusX="5" RadiusY="5" />
                </Setter.Value>
            </Setter>
        </Style>
    </Grid.Resources>
    <Canvas Grid.Column="1">
        <Canvas.RenderTransform>
            <TransformGroup>
                <ScaleTransform ScaleY="-1" />
                <TranslateTransform Y="100" />
            </TransformGroup>
        </Canvas.RenderTransform>

        <Line X1="0" Y1="0" X2="100" Y2="100" Stroke="Black" />
        <Polyline Points="0 0 0 100 100 100 100 0 0 0" Stroke="Blue" />
        <Path />
    </Canvas>

</Grid>

   
    
    
    
    
    
     


Set cursor area

image_pdfimage_print
   
  

<Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="cursors" Height="450" Width="600" Loaded="OnLoaded">
  <Window.Resources>
    <Style TargetType="{x:Type RadioButton}">
      <Setter Property="Margin" Value="3" />
    </Style>
    <Style TargetType="{x:Type Label}">
      <Setter Property="FontSize" Value="14" />
      <Setter Property="HorizontalAlignment" Value="Center" />
    </Style>
    <Style TargetType="{x:Type Border}">
      <Setter Property="BorderBrush" Value="LightBlue" />
      <Setter Property="BorderThickness" Value="2" />
      <Setter Property="Margin" Value="10" />
    </Style>
  </Window.Resources>

  <StackPanel>
    <Border Width="300">
      <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
        <StackPanel Margin="10">
          <Label HorizontalAlignment="Left">Cursor Type</Label>
          <ComboBox Width="100" SelectionChanged="CursorTypeChanged" HorizontalAlignment="Left" Name="CursorSelector">
            <ComboBoxItem Content="AppStarting" />
            <ComboBoxItem Content="ArrowCD" />
          </ComboBox>
        </StackPanel>
        <StackPanel Margin="10">
          <Label HorizontalAlignment="Left">Scope of Cursor</Label>
          <StackPanel>
            <RadioButton Name="rbScopeElement" IsChecked="True" Checked="CursorScopeSelected">Display Area Only</RadioButton>
            <RadioButton Name="rbScopeApplication" Checked="CursorScopeSelected">Entire Appliation</RadioButton>
          </StackPanel>
        </StackPanel>
      </StackPanel>
    </Border>
    <Border Name="DisplayArea" Height="250" Width="400" Margin="20" Background="AliceBlue">
      <Label HorizontalAlignment="Center">
        Move Mouse Pointer Over This Area
      </Label>
    </Border>
  </StackPanel>
</Window>

//File:Window.xaml.cs

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Input;
using System.IO;
using System.Collections;


namespace WpfApplication1
{
    public partial class Window1 : Window
    {
        Cursor CustomCursor;
       
        public Window1()
        {
            CustomCursor = new Cursor(Directory.GetCurrentDirectory() +Path.DirectorySeparatorChar + "CustomCursor.cur");
        }
        public void CursorTypeChanged(object sender, SelectionChangedEventArgs e)
        {
            ComboBox source = e.Source as ComboBox;

            if (source != null)
            {
                ComboBoxItem selectedCursor = source.SelectedItem as ComboBoxItem;
                
                switch (selectedCursor.Content.ToString())
                {
                    case "AppStarting":
                        DisplayArea.Cursor = Cursors.AppStarting;
                        break;
                    case "ArrowCD":                        
                        DisplayArea.Cursor = Cursors.ArrowCD;
                        break;
                    default:
                        break;
                }

                if (cursorScopeElementOnly == false)
                {
                    Mouse.OverrideCursor = DisplayArea.Cursor;
                }
            }
        }
        public void CursorScopeSelected(object sender, RoutedEventArgs e)
        {
            RadioButton source = e.Source as RadioButton;

            if (source != null)
            {
                if (source.Name == "rbScopeElement")
                {
                    cursorScopeElementOnly = true;
                    Mouse.OverrideCursor = null;
                }
                if (source.Name == "rbScopeApplication")
                {
                   cursorScopeElementOnly = false;
                   Mouse.OverrideCursor = DisplayArea.Cursor;
                }
            }
        }
        public void OnLoaded(object sender, RoutedEventArgs e)
        {
            ((ComboBoxItem)CursorSelector.Items[0]).IsSelected = true;
        }
        private bool cursorScopeElementOnly = true;
    }
}

   
    
     


Changing the cursor of the Border control by setting the Cursor property

image_pdfimage_print
   
  

<Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="cursors" Height="450" Width="600" Loaded="OnLoaded">
  <Window.Resources>
    <Style TargetType="{x:Type RadioButton}">
      <Setter Property="Margin" Value="3" />
    </Style>
    <Style TargetType="{x:Type Label}">
      <Setter Property="FontSize" Value="14" />
      <Setter Property="HorizontalAlignment" Value="Center" />
    </Style>
    <Style TargetType="{x:Type Border}">
      <Setter Property="BorderBrush" Value="LightBlue" />
      <Setter Property="BorderThickness" Value="2" />
      <Setter Property="Margin" Value="10" />
    </Style>
  </Window.Resources>

  <StackPanel>
    <Border Width="300">
      <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
          <Label HorizontalAlignment="Left">Cursor Type</Label>
          <ComboBox Width="100" SelectionChanged="CursorTypeChanged" HorizontalAlignment="Left" Name="CursorSelector">
            <ComboBoxItem Content="AppStarting" />
            <ComboBoxItem Content="ArrowCD" />
            <ComboBoxItem Content="Arrow" />
            <ComboBoxItem Content="Cross" />
            <ComboBoxItem Content="HandCursor" />
            <ComboBoxItem Content="Help" />
            <ComboBoxItem Content="IBeam" />
            <ComboBoxItem Content="No" />
            <ComboBoxItem Content="None" />
            <ComboBoxItem Content="Pen" />
            <ComboBoxItem Content="ScrollSE" />
            <ComboBoxItem Content="ScrollWE" />
            <ComboBoxItem Content="SizeAll" />
            <ComboBoxItem Content="SizeNESW" />
            <ComboBoxItem Content="SizeNS" />
            <ComboBoxItem Content="SizeNWSE" />
            <ComboBoxItem Content="SizeWE" />
            <ComboBoxItem Content="UpArrow" />
            <ComboBoxItem Content="WaitCursor" />
            <ComboBoxItem Content="Custom" />
          </ComboBox>
      </StackPanel>
    </Border>
    <Border Name="DisplayArea" Height="250" Width="400" Margin="20" Background="AliceBlue">
      <Label HorizontalAlignment="Center">
        Move Mouse Pointer Over This Area
      </Label>
    </Border>
  </StackPanel>
</Window>

//File:Window.xaml.cs

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Input;
using System.IO;
using System.Collections;


namespace WpfApplication1
{
    public partial class Window1 : Window
    {
        Cursor CustomCursor;
       
        public Window1()
        {
            CustomCursor = new Cursor(Directory.GetCurrentDirectory() +Path.DirectorySeparatorChar + "CustomCursor.cur");
        }
        public void CursorTypeChanged(object sender, SelectionChangedEventArgs e)
        {
            ComboBox source = e.Source as ComboBox;

            if (source != null)
            {
                ComboBoxItem selectedCursor = source.SelectedItem as ComboBoxItem;
                
                switch (selectedCursor.Content.ToString())
                {
                    case "AppStarting":
                        DisplayArea.Cursor = Cursors.AppStarting;
                        break;
                    case "ArrowCD":                        
                        DisplayArea.Cursor = Cursors.ArrowCD;
                        break;
                    case "Arrow":
                        DisplayArea.Cursor = Cursors.Arrow;
                        break;
                    case "Cross":
                        DisplayArea.Cursor = Cursors.Cross;
                        break;
                    case "HandCursor":
                        DisplayArea.Cursor = Cursors.Hand;
                        break;
                    case "Help":
                        DisplayArea.Cursor = Cursors.Help;
                        break;
                    case "IBeam":
                        DisplayArea.Cursor = Cursors.IBeam;
                        break;
                    case "No":
                        DisplayArea.Cursor = Cursors.No;
                        break;
                    case "None":
                        DisplayArea.Cursor = Cursors.None;
                        break;
                    case "Pen":
                        DisplayArea.Cursor = Cursors.Pen;
                        break;
                    case "ScrollSE":
                        DisplayArea.Cursor = Cursors.ScrollSE;
                        break;
                    case "ScrollWE":
                        DisplayArea.Cursor = Cursors.ScrollWE;
                        break;
                    case "SizeAll":
                        DisplayArea.Cursor = Cursors.SizeAll;
                        break;
                    case "SizeNESW":
                        DisplayArea.Cursor = Cursors.SizeNESW;
                        break;
                    case "SizeNS":
                        DisplayArea.Cursor = Cursors.SizeNS;
                        break;
                    case "SizeNWSE":
                        DisplayArea.Cursor = Cursors.SizeNWSE;
                        break;
                    case "SizeWE":
                        DisplayArea.Cursor = Cursors.SizeWE;
                        break;
                    case "UpArrow":
                        DisplayArea.Cursor = Cursors.UpArrow;
                        break;
                    case "WaitCursor":
                        DisplayArea.Cursor = Cursors.Wait;
                        break;
                    case "Custom":
                        DisplayArea.Cursor = CustomCursor;
                        break;
                    default:
                        break;
                }
            }
        }
        public void OnLoaded(object sender, RoutedEventArgs e)
        {
            ((ComboBoxItem)CursorSelector.Items[0]).IsSelected = true;
        }
    }
}

   
    
     


Cubic Bezier, Smooth Bezier, Quadratic Bezier, Smooth Quadratic

image_pdfimage_print


   
     

<Window x:Class="Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="BezierCurves" Height="200" Width="500">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="0.25*" />
            <ColumnDefinition Width="0.25*" />
            <ColumnDefinition Width="0.25*" />
            <ColumnDefinition Width="0.25*" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="50" />
            <RowDefinition Height="1.0*" />
        </Grid.RowDefinitions>

        <Path Stroke="Gray" StrokeThickness="5" Data="M 210,20 L 80,20 30,100 80,810" Grid.Column="0" Grid.Row="1" />
        <Path Stroke="Black" StrokeThickness="1" Data="M 210,20 C 80,20 30,100 80,810" Grid.Column="0" Grid.Row="1" />

        <Path Stroke="Gray" StrokeThickness="5" Grid.Column="1" Data="M 210,20 L 80,20 50,60 90,100 50,120" Grid.Row="1" />
        <Path Stroke="Black" StrokeThickness="1" Grid.Column="1" Data="M 210,20 S 80,20 50,60 S 90,100 50,120" Grid.Row="1" />

        <Path Stroke="Gray" StrokeThickness="5" Grid.Column="2" Data="M 210,20 L 80,20 50,60 90,100 50,120" Grid.Row="1" />
        <Path Stroke="Black" StrokeThickness="1" Grid.Column="2" Data="M 210,20 Q 80,20 50,60 Q 90,100 50,120" Grid.Row="1" />

        <Path Stroke="Gray" StrokeThickness="5" Grid.Column="3" Data="M 210,20 L 80,20 50,60 90,100" Grid.Row="1" />
        <Path Stroke="Black" StrokeThickness="1" Grid.Column="3" Data="M 210,20 T 80,20 T 50,60 T 90,100" Grid.Row="1" />

    </Grid>
</Window>

   
    
    
    
    
     


DataContextProperty.OverrideMetadata to update DataContext

image_pdfimage_print


   
  
<Window x:Class="WpfApplication1.Window1"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  Title="Window1" Height="100" Width="200">
  <StackPanel>
    <TextBox x:Name="tbxUserText" Text="Enter some text..."/>
    <Button Click="Button_Click" Content="Update DataContext"/>
  </StackPanel>
</Window>

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

namespace WpfApplication1
{
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
            DataContextProperty.OverrideMetadata(
                typeof(Window1), 
                new FrameworkPropertyMetadata(
                        100d, 
                        new PropertyChangedCallback(DataContext_PropertyChanged)));

        }

        private static void DataContext_PropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            string msg = string.Format("DataContext changed.{0}{0}Old Value: {1}{0}New Value: {2}",
                              Environment.NewLine,
                              e.OldValue.ToString(), 
                              e.NewValue.ToString());

            MessageBox.Show(msg, "changed");
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            DataContext = tbxUserText.Text;            
        }
    }
}

   
    
     


Listen to DataContent changed event

image_pdfimage_print


   
  

<Window x:Class="WpfApplication1.Window1"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  Title="Window1" Height="100" Width="200">
  <StackPanel>
    <TextBox x:Name="tbxUserText" Text="Enter some text..."/>
    <Button Click="Button_Click" Content="Update DataContext"/>
  </StackPanel>
</Window>

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

namespace WpfApplication1
{
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
            DataContextProperty.OverrideMetadata(
                typeof(Window1), 
                new FrameworkPropertyMetadata(
                        100d, 
                        new PropertyChangedCallback(DataContext_PropertyChanged)));

        }

        private static void DataContext_PropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            string msg = string.Format("DataContext changed.{0}{0}Old Value: {1}{0}New Value: {2}",
                              Environment.NewLine,
                              e.OldValue.ToString(), 
                              e.NewValue.ToString());

            MessageBox.Show(msg, "changed");
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            DataContext = tbxUserText.Text;            
        }
    }
}