The resulting ellipse's outline is painted with an image

image_pdfimage_print


   
      
<Page  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
   x:Class="Microsoft.Samples.Graphics.UsingImageBrush.TilingExample" >

  <Grid Margin="20">
    <Ellipse Grid.Row="6" Grid.Column="0" Height="150" Width="150" StrokeThickness="20"
     HorizontalAlignment="Left">
      <Ellipse.Stroke>
        <ImageBrush ImageSource="c:image.jpg" Viewport="-10,-10,160,160" ViewportUnits="Absolute" />
      </Ellipse.Stroke>
    </Ellipse>

  </Grid>
</Page>

   
    
    
    
    
    
     


Ellipse Mouse Down 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="MouseInput" Height="300" Width="300">
    <Grid>
      <Ellipse Fill="Blue" x:Name="myEllipse" />
    </Grid>
</Window>


//File:Window.xaml.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Diagnostics;


namespace WpfApplication1
{
    public partial class Window1 : System.Windows.Window
    {
        public Window1()
        {
            InitializeComponent();

            myEllipse.MouseDown += myEllipse_MouseDown;

        }

        void myEllipse_MouseDown(object sender, MouseButtonEventArgs e)
        {
            Mouse.Capture(myEllipse);
        }


    }
}

   
    
     


DateTemplate for Date Time, filter value by path

image_pdfimage_print


   
  
<Page 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">
    <Page.Resources>

        <DataTemplate DataType="{x:Type s:DateTime}">
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="DateTime: " />
                <TextBlock Text="{Binding Path=Month}" />
                <TextBlock Text="/" />
                <TextBlock Text="{Binding Path=Day}" />
                <TextBlock Text="/" />
                <TextBlock Text="{Binding Path=Year}" />
            </StackPanel>
        </DataTemplate>

    </Page.Resources>

    <StackPanel>
        <Button>
            <x:Static Member="s:DateTime.Now" />
        </Button>

    </StackPanel>
</Page>

   
    
     


DateTemplate for String

image_pdfimage_print


   
  

<Page 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">
    <Page.Resources>

        <DataTemplate DataType="{x:Type s:String}">
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="String: " />
                <TextBlock Text="{Binding}" />
            </StackPanel>
        </DataTemplate>

    </Page.Resources>

    <StackPanel>
        <Button>
            <s:String>1</s:String>
        </Button>

    </StackPanel>
</Page>

   
    
     


Use Data Templates to Display Bound Data

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"
    xmlns:WpfApplication1="clr-namespace:WpfApplication1"
    Title="WPF" Height="300" Width="300">

    <Window.Resources>
        <WpfApplication1:People x:Key="people"/>
        
        <DataTemplate x:Key="personTemplate">
                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="80"/>
                        <ColumnDefinition Width="*"/>
                    </Grid.ColumnDefinitions>

                    <StackPanel>
                        <TextBlock
                            Style="{StaticResource lblStyle}"
                            Text="First Name" />
                        <TextBlock 
                            Style="{StaticResource dataStyle}"
                            Text="{Binding Path=FirstName}"/>
                        <TextBlock 
                            Style="{StaticResource lblStyle}"
                            Text="Age" />
                        <TextBlock 
                            Style="{StaticResource dataStyle}"
                            Text="{Binding Path=Age}" />
                    </StackPanel>

                    <Image 
                        Margin="4"
                        Grid.Column="1" 
                        Width="96"
                        Height="140"
                        Source="{Binding Path=Photo}"/>
                </Grid>
        </DataTemplate>


    </Window.Resources>

    <Grid>
        <ListBox
            ItemsSource="{Binding Source={StaticResource people}}"
            ItemTemplate="{StaticResource personTemplate}"/>


        <ListBox
            Margin="10"
            ItemsSource="{Binding Source={StaticResource people}}"/>
    </Grid>
</Window>
//File:Window.xaml.cs
using System.Collections.ObjectModel;

namespace WpfApplication1
{
    public class Employee
    {
        public string FirstName
        {
            get;
            set;
        }

        public int Age
        {
            get;
            set;
        }
        public string Photo
        {
            get;
            set;
        }

        public override string ToString()
        {
            return FirstName;
        }
    }

    public class People : Collection<Employee>
    {
        public People()
        {
            this.Add(new Employee()
                         {
                             FirstName = "A",
                             Age = 26,
                             Photo = "a.png"
                         });
            this.Add(new Employee()
                         {
                             FirstName = "C",
                             Age = 24,
                             Photo = "c.png"
                         });
        }
    }
}

   
    
     


Use DataTemplate, DataTrigger, and DataTemplateSelector to specify the presentation of your data

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"
  xmlns:local="clr-namespace:WpfApplication1"
  Title="Introduction to Data Templating Sample">
  <Window.Resources>
    <local:Employees x:Key="myTodoList"/>
    <local:EmployeeListDataTemplateSelector x:Key="myDataTemplateSelector"/>
    <DataTemplate x:Key="importantEmployeeTemplate">
      <DockPanel HorizontalAlignment="Center">
          <TextBlock Text="{Binding Path=Description}" />
      </DockPanel>
    </DataTemplate>
    <DataTemplate x:Key="myEmployeeTemplate">
    <StackPanel>
          <TextBlock Text="Employee Name:"/>
          <TextBlock Text="{Binding Path=EmployeeName}" />
          <TextBlock Text="Description:"/>
          <TextBlock Text="{Binding Path=Description}"/>
          <TextBlock Text="Priority:"/>
          <TextBlock Text="{Binding Path=Priority}"/>
    </StackPanel>
    <DataTemplate.Triggers>
      <DataTrigger Binding="{Binding Path=EmployeeType}">
        <DataTrigger.Value>
          <local:EmployeeType>Factory</local:EmployeeType>
        </DataTrigger.Value>
      </DataTrigger>
    </DataTemplate.Triggers>
    </DataTemplate>
  </Window.Resources>
  <StackPanel>
    <ListBox ItemsSource="{Binding Source={StaticResource myTodoList}}"
             ItemTemplateSelector="{StaticResource myDataTemplateSelector}"
             HorizontalContentAlignment="Stretch" 
             IsSynchronizedWithCurrentItem="True"/>
    <ContentControl Content="{Binding Source={StaticResource myTodoList}}"
                    ContentTemplate="{StaticResource myEmployeeTemplate}"/>
  </StackPanel>
</Window>


//File:Window.xaml.cs
using System;
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Data;
using System.Windows.Media;
using System.Collections.ObjectModel;
using System.ComponentModel;

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

  public class Employee : INotifyPropertyChanged
  {
      private string name;
      private string description;
      private int priority;
      private EmployeeType type;


      public event PropertyChangedEventHandler PropertyChanged;

      public Employee()
      {
      }

      public Employee(string name, string description, int priority, EmployeeType type)
      {
          this.name = name;
          this.description = description;
          this.priority = priority;
          this.type = type;
      }

      public override string ToString()
      {
          return name.ToString();
      }

      public string EmployeeName
      {
          get { return name; }
          set
          {
              name = value;
              OnPropertyChanged("EmployeeName");
          }
      }

      public string Description
      {
          get { return description; }
          set
          {
              description = value;
              OnPropertyChanged("Description");
          }
      }

      public int Priority
      {
          get { return priority; }
          set
          {
              priority = value;
              OnPropertyChanged("Priority");
          }
      }

      public EmployeeType EmployeeType
      {
          get { return type; }
          set
          {
              type = value;
              OnPropertyChanged("EmployeeType");
          }
      }

      protected void OnPropertyChanged(string info)
      {
          PropertyChangedEventHandler handler = PropertyChanged;
          if (handler != null)
          {
              handler(this, new PropertyChangedEventArgs(info));
          }
      }
  }
    public class Employees : ObservableCollection<Employee>
    {
        public Employees(): base()
        {
            Add(new Employee("A", "Cut", 2, EmployeeType.Factory));
            Add(new Employee("B", "Fix", 2, EmployeeType.Factory));
            Add(new Employee("C", "Email", 1, EmployeeType.Office));
            Add(new Employee("D", "Read", 3, EmployeeType.Office));
            Add(new Employee("E", "Clean", 1, EmployeeType.Factory));
            Add(new Employee("F", "Review", 2, EmployeeType.Office));
        }
    }

    public enum EmployeeType
    {
        Factory,
        Office
    }
    public class EmployeeListDataTemplateSelector : DataTemplateSelector
    {
        public override DataTemplate
            SelectTemplate(object item, DependencyObject container)
        {
            if (item != null &amp;&amp; item is Employee)
            {
                Employee taskitem = item as Employee;
                Window window = Application.Current.MainWindow;

                if (taskitem.Priority == 1)
                    return
                        window.FindResource("importantEmployeeTemplate") as DataTemplate;
                else
                    return
                        window.FindResource("myEmployeeTemplate") as DataTemplate;
            }

            return null;
        }
    }
}