Create a simple polyline, a closed polyline. And a Sine curve in code.

image_pdfimage_print












//File:Window.xaml.cs

using System;
using System.Windows;
using System.Windows.Media;
using System.Windows.Shapes;

namespace WpfApplication1
{
public partial class Polylines : Window
{
public Polylines()
{
InitializeComponent();
for (int i = 0; i < 70; i++) { double x = i * Math.PI; double y = 40 + 30 * Math.Sin(x / 10); polyline1.Points.Add(new Point(x, y)); } } } } [/csharp]

Populate the PointsCollection of the PolyLine

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="WPF" Height="270" Width="300" Loaded="Window_Loaded">
    <Canvas>
        <TextBlock Canvas.Top="40" Canvas.Left="20"
                   FontSize="14" Text="Static Points Collection" />
        <Polyline Stroke="Black" StrokeThickness="3" 
                  Points="0,0 300,10 300,10 10,10 10,25
                  250,250 255,85 250,40 205,85 200,40 155,85 35,90" />
        <TextBlock Canvas.Top="150" Canvas.Left="20" Text="Programmatic Points Collection" />
        <Polyline Name="plLine" Stroke="Black" StrokeThickness="3" />
    </Canvas>
</Window>
//File:Window.xaml.cs
using System.Windows;

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

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
         
            plLine.Points.Add(new Point(10, 140));
            plLine.Points.Add(new Point(270, 140));
            plLine.Points.Add(new Point(10, 175));
            plLine.Points.Add(new Point(10, 220));
            plLine.Points.Add(new Point(125, 220));
        }
    }
}

   
    
     


Draw a Sequence of Connected Lines

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="WPF" Height="270" Width="300" Loaded="Window_Loaded">
    <Canvas>
        <TextBlock Canvas.Top="40" Canvas.Left="20"
                   FontSize="14" Text="Static Points Collection" />
        <Polyline Stroke="Black" StrokeThickness="3" 
                  Points="0,0 300,10 300,10 10,10 10,25
                  250,250 255,85 250,40 205,85 200,40 155,85 35,90" />
        <TextBlock Canvas.Top="150" Canvas.Left="20" Text="Programmatic Points Collection" />
        <Polyline Name="plLine" Stroke="Black" StrokeThickness="3" />
    </Canvas>
</Window>
//File:Window.xaml.cs
using System.Windows;

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

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
         
            plLine.Points.Add(new Point(10, 140));
            plLine.Points.Add(new Point(270, 140));
            plLine.Points.Add(new Point(10, 175));
            plLine.Points.Add(new Point(10, 220));
            plLine.Points.Add(new Point(125, 220));
        }
    }
}

   
    
     


Create an animated Popup control.

image_pdfimage_print
   
     

<Window x:Class="SDKSample.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="AnimatedPopup">
  <StackPanel>
    <CheckBox Name="myCheckBox" Margin="20,20,0,0" Content="Select CheckBox to see Popup"/>
    <Button HorizontalAlignment="Left" Width="200" Margin="20,10,0,0">
      <Button.Triggers>
        <EventTrigger RoutedEvent="Button.Click">
          <BeginStoryboard>
            <Storyboard>
              <DoubleAnimation 
                Storyboard.TargetName="theTransform"
                Storyboard.TargetProperty="(RotateTransform.Angle)" 
                From="0" To="360" Duration="0:0:5" AutoReverse="True"/>
            </Storyboard>
          </BeginStoryboard>
        </EventTrigger>
      </Button.Triggers>
      Click to see the Popup animate
    </Button>


  </StackPanel>
</Window>

   
    
    
    
    
     


Rotating Popup

image_pdfimage_print


   
     

<Window x:Class="SDKSample.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="AnimatedPopup">
  <StackPanel>
    <Popup IsOpen="{Binding ElementName=myCheckBox,Path=IsChecked}" 
           PlacementTarget="{Binding ElementName=myCheckBox}"            
           AllowsTransparency="True"
           PopupAnimation="Slide"
           HorizontalOffset="50"
           VerticalOffset="50"
           >
      <Canvas Width="100" Height="100" Background="DarkBlue"
              Margin="150">
        <Canvas.RenderTransform>
          <RotateTransform x:Name="theTransform" />
        </Canvas.RenderTransform>
        <TextBlock TextWrapping="Wrap" Foreground="White">
          Rotating Popup
        </TextBlock>
      </Canvas>
    </Popup>


  </StackPanel>
</Window>

   
    
    
    
    
     


Create Popup mock in Xaml

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="WPF" Height="150" Width="250">
    <StackPanel>
        <Popup AllowsTransparency="True" Height="100" HorizontalOffset="1cm" Name="myPopup" 
                   Placement="Right" StaysOpen="True" Width="200" >
            <Border BorderBrush="Black" BorderThickness="2">
                <DockPanel Background="White" LastChildFill="True">
                    <TextBlock Background="AliceBlue" DockPanel.Dock="Top" 
                                   FontSize="16" HorizontalAlignment="Stretch" 
                                   Margin="5" Text="A WPF Popup" />
                        <Button Click="btnClosePopup_Click" Content="Close" 
                                DockPanel.Dock="Bottom" Margin="5" 
                                HorizontalAlignment="Right" MaxHeight="23"/>
                        <Image DockPanel.Dock="Top" Margin="5" 
                               Source="c:image.gif" />
                    </DockPanel>
            </Border>
        </Popup>
        <StackPanel>
            <StackPanel.Resources>
                <Style TargetType="{x:Type Button}">
                    <Setter Property="Margin" Value="2" />                        
                    <EventSetter Event="Click" Handler="btnShowPopup_Click" />
                </Style>
            </StackPanel.Resources>
            <Button Content="Show Popup" Name="btnShowPopup" />
        </StackPanel>
    </StackPanel>
</Window>

//File:Window.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
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.Navigation;
using System.Windows.Shapes;
using System.Windows.Controls.Primitives;

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

        private void btnClosePopup_Click(object sender, RoutedEventArgs e)
        {
            myPopup.IsOpen = false;
        }

        private void btnShowPopup_Click(object sender, RoutedEventArgs e)
        {
            myPopup.IsOpen = true;
        }
    }
}

   
    
     


Close a Popup with Button click

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="WPF" Height="150" Width="250">
    <StackPanel>
        <Popup AllowsTransparency="True" Height="100" HorizontalOffset="1cm" Name="myPopup" 
                   Placement="Right" StaysOpen="True" Width="200" >
            <Border BorderBrush="Black" BorderThickness="2">
                <DockPanel Background="White" LastChildFill="True">
                    <TextBlock Background="AliceBlue" DockPanel.Dock="Top" 
                                   FontSize="16" HorizontalAlignment="Stretch" 
                                   Margin="5" Text="A WPF Popup" />
                        <Button Click="btnClosePopup_Click" Content="Close" 
                                DockPanel.Dock="Bottom" Margin="5" 
                                HorizontalAlignment="Right" MaxHeight="23"/>
                        <Image DockPanel.Dock="Top" Margin="5" 
                               Source="c:image.gif" />
                    </DockPanel>
            </Border>
        </Popup>
        <StackPanel>
            <StackPanel.Resources>
                <Style TargetType="{x:Type Button}">
                    <Setter Property="Margin" Value="2" />                        
                    <EventSetter Event="Click" Handler="btnShowPopup_Click" />
                </Style>
            </StackPanel.Resources>
            <Button Content="Show Popup" Name="btnShowPopup" />
        </StackPanel>
    </StackPanel>
</Window>

//File:Window.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
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.Navigation;
using System.Windows.Shapes;
using System.Windows.Controls.Primitives;

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

        private void btnClosePopup_Click(object sender, RoutedEventArgs e)
        {
            myPopup.IsOpen = false;
        }

        private void btnShowPopup_Click(object sender, RoutedEventArgs e)
        {
            if (sender == btnShowPopup){
            
                myPopup.IsOpen = true;
            } 
        }
    }
}