Large ArcSegments

image_pdfimage_print


   
      

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      HorizontalAlignment="Stretch" VerticalAlignment="Stretch">


<Canvas>
  <Ellipse Fill="Cyan" Stroke="Black" Width="140" Height="60" />
  <Path Fill="Cyan" Stroke="Black" Canvas.Left="180">
    <Path.Data>
      <PathGeometry>

        <PathFigure StartPoint="240,1" IsClosed="True">
          <ArcSegment Point="290,51" Size="70,30"
                      SweepDirection="Counterclockwise" IsLargeArc="True" />
        </PathFigure>

      </PathGeometry>
    </Path.Data>
  </Path>
</Canvas>


</Page>

   
    
    
    
    
    
     


Clear Controls

image_pdfimage_print


   
  
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Class="ElemCollMethods.Pane1"
    WindowTitle="UI Element Collection Methods Sample">
 <StackPanel>
    <TextBlock Name="txt" FontSize="16">UI Element Collection - Methods</TextBlock>

    <TabControl>
    
        <TabItem MouseLeftButtonUp="ClearButtons">
            <TabItem.Header>Clear Controls</TabItem.Header>
        </TabItem>
    </TabControl>
    <StackPanel Name="sp1"></StackPanel>

 </StackPanel>
</Page>

//File:Window.xaml.cs
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Data;
using System.Windows.Input;

namespace ElemCollMethods
{

  public partial class Pane1 : Page
  {
    System.Windows.Controls.Button btn, btn1, btn2, btn3;


    void ClearButtons(object sender, MouseButtonEventArgs e)
    {
            sp1.Children.Clear();
            btn = new Button();
      btn.Content = "Click to clear";
            sp1.Children.Add(btn);
            btn.Click += (ClearControls);
      btn1 = new Button();
      btn1.Content = "Click to clear";
            sp1.Children.Add(btn1);
            btn1.Click += (ClearControls);
      btn2 = new Button();
      btn2.Content = "Click to clear";
            sp1.Children.Add(btn2);
            btn2.Click += (ClearControls);
      btn3 = new Button();
      btn3.Content = "Click to clear";
            sp1.Children.Add(btn3);
            btn3.Click += (ClearControls);
    }
        
    void ClearControls(object sender, RoutedEventArgs e)
    {
            sp1.Children.Clear();
        }    
  }
}

   
    
     


Contains Element?

image_pdfimage_print


   
  
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Class="ElemCollMethods.Pane1"
    WindowTitle="UI Element Collection Methods Sample">
 <StackPanel>
    <TextBlock Name="txt" FontSize="16">UI Element Collection - Methods</TextBlock>

    <TabControl>
        <TabItem MouseLeftButtonUp="ContainsElement">
            <TabItem.Header>Contains Element?</TabItem.Header>
        </TabItem>
    </TabControl>
    <StackPanel Name="sp1"></StackPanel>

 </StackPanel>
</Page>
//File:Window.xaml.cs

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Data;
using System.Windows.Input;

namespace ElemCollMethods
{

  public partial class Pane1 : Page
  {
    System.Windows.Controls.Button btn, btn1, btn2, btn3;

        void ContainsElement(object sender, RoutedEventArgs e)
        {
            sp1.Children.Clear();
            btn = new Button();
      btn.Content = "Click to clear";
            sp1.Children.Add(btn);
            btn.Click += (ClearControls);
      btn1 = new Button();
      btn1.Content = "Click to clear";
            sp1.Children.Add(btn1);
            btn1.Click += (ClearControls);
      btn2 = new Button();
      btn2.Content = "Click to clear";
            sp1.Children.Add(btn2);
            btn2.Click += (ClearControls);
      btn3 = new Button();
      btn3.Content = "Click to clear";
            sp1.Children.Add(btn3);
            btn3.Click += (ClearControls);

            TextBlock txt1 = new TextBlock();
            sp1.Children.Add(txt1);
            txt1.Text = "This StackPanel contains UIElement btn1: " + sp1.Children.Contains(btn1).ToString();
        }
        
    void ClearControls(object sender, RoutedEventArgs e)
    {
            sp1.Children.Clear();
        }        
  }
}

   
    
     


UIElement Count

image_pdfimage_print


   
  
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Class="ElemCollMethods.Pane1"
    WindowTitle="UI Element Collection Methods Sample">
 <StackPanel>
    <TextBlock Name="txt" FontSize="16">UI Element Collection - Methods</TextBlock>

    <TabControl>
        <TabItem MouseLeftButtonUp="GetCount">
            <TabItem.Header>UIElement Count</TabItem.Header>
        </TabItem>
    </TabControl>
    <StackPanel Name="sp1"></StackPanel>

 </StackPanel>
</Page>

//File:Window.xaml.cs
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Data;
using System.Windows.Input;

namespace ElemCollMethods
{

  public partial class Pane1 : Page
  {
    System.Windows.Controls.Button btn, btn1, btn2, btn3;



        void GetCount(object sender, RoutedEventArgs e)
        {
            TextBlock txt3 = new TextBlock();
            sp1.Children.Add(txt3);
            txt3.Text = "UIElement Count is equal to " + sp1.Children.Count.ToString();
        }
  }
}

   
    
     


Get Item At Index Position [0]

image_pdfimage_print


   
  

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Class="ElemCollMethods.Pane1"
    WindowTitle="UI Element Collection Methods Sample">
 <StackPanel>
    <TextBlock Name="txt" FontSize="16">UI Element Collection - Methods</TextBlock>

    <TabControl>
        <TabItem MouseLeftButtonUp="GetItem">
           <TabItem.Header>Get Item At Index Position [0]</TabItem.Header>
        </TabItem>
    </TabControl>
    <StackPanel Name="sp1"></StackPanel>

 </StackPanel>
</Page>

//File:Window.xaml.cs
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Data;
using System.Windows.Input;

namespace ElemCollMethods
{

  public partial class Pane1 : Page
  {
    System.Windows.Controls.Button btn, btn1, btn2, btn3;


        void GetItem(object sender, RoutedEventArgs e)
        {
            TextBlock txt2 = new TextBlock();
            sp1.Children.Add(txt2);
            txt2.Text = "UIElement at Index position [0] is " + sp1.Children[0].ToString();
        }
  }
}

   
    
     


Panel is setting the data context to the scrollbar object

image_pdfimage_print


   
  

<Window x:Class="WpfApplication1.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:myConverters ="clr-namespace:WpfApplication1" 
    Title="Simple Data Binding" Height="334" Width="288" 
    WindowStartupLocation="CenterScreen" 
    >
  <Window.Resources>
    <myConverters:MyDoubleConverter x:Key="DoubleConverter"/>
    <myConverters:MyColorConverter x:Key="ColorConverter"/>
  </Window.Resources>
    <StackPanel Width="250" DataContext = "{Binding ElementName=mySB}">
     <ScrollBar Orientation="Horizontal" Name="mySB" Maximum = "100" LargeChange="1" SmallChange="1"/>
     <TextBox Name="txtThumbValue" Text = "{Binding Path=Value, Converter={StaticResource DoubleConverter}}"/>
     <Button Content="Click" FontSize = "{Binding Path=Value}" Background= "{Binding Path=Value, Converter={StaticResource ColorConverter}}"/>
  </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.Collections.Generic;
namespace WpfApplication1
{
  public partial class MainWindow : Window
  {
    public MainWindow()
    {
      InitializeComponent();      
    }
  }

  class MyColorConverter : IValueConverter
  {
    public object Convert(object value, Type targetType, object parameter, 
      System.Globalization.CultureInfo culture)
    {
      double d = (double)value;
      byte v = (byte)d;

      Color color = new Color();
      color.A = 255;
      color.G = (byte) (155 + v);

      return new SolidColorBrush(color);
    }

    public object ConvertBack(object value, Type targetType, object parameter, 
      System.Globalization.CultureInfo culture)
    {
      return value;
    }
  }

  class MyDoubleConverter : IValueConverter 
  {
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
      double v = (double)value;
      return (int)v;
    }

    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
      return value;
    } 
  }
}