Search for an element by using Panel.FindName()

image_pdfimage_print


   
  

<StackPanel Name="root"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  x:Class="WpfApplication1.FEFindName">
  <StackPanel.Resources>
      <Style TargetType="{x:Type Button}">
        <Setter Property="Height" Value="20"/>
        <Setter Property="Width" Value="250"/>
        <Setter Property="HorizontalAlignment" Value="Left"/>
      </Style>
      <Style TargetType="{x:Type TextBlock}">
        <Setter Property="HorizontalAlignment" Value="Left"/>
        <Setter Property="FontSize" Value="20"/>
      </Style>
  </StackPanel.Resources>
  <Button Click="Find">Find element with the ID "dog" and change color</Button>
  <StackPanel Name="stackPanel">
    <TextBlock Name="cat">Cat</TextBlock>
    <TextBlock Name="dog">Dog</TextBlock>
    <TextBlock Name="fish">Fish</TextBlock>    
  </StackPanel>
</StackPanel>
//File:Window.xaml.cs

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace WpfApplication1
{
    public partial class FEFindName {
        void Find(object sender, RoutedEventArgs e)
        {
            object wantedNode = stackPanel.FindName("dog");
            if (wantedNode is TextBlock)
            {
                TextBlock wantedChild = wantedNode as TextBlock;
                wantedChild.Foreground = Brushes.Blue;
            }
        }
    }
}

   
    
     


Password for PasswordBox

image_pdfimage_print


   
   

<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>
      <HeaderedItemsControl Header="TextBox">
        <StackPanel>
          <TextBox HorizontalAlignment="Center" Margin="8" Text="Edit Me" />
          <PasswordBox HorizontalAlignment="Center" Margin="8" Password="Password" />
        </StackPanel>
      </HeaderedItemsControl>
   
    </WrapPanel>
  </ScrollViewer>
</Window>

   
    
    
     


Display a Password Entry Box and get the input

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="100" Width="300">
    <StackPanel Orientation="Horizontal">
        <TextBlock Margin="5" VerticalAlignment="Center">
            Enter Password:
        </TextBlock>
        <PasswordBox Name="passwordBox" PasswordChar="!" 
                     VerticalAlignment="Center" Width="150" />
        <Button Content="OK" IsDefault="True" Margin="5" Name="button1" 
                VerticalAlignment="Center" Click="button1_Click" />
    </StackPanel>
</Window>
//File:Window.xaml.cs
using System.Windows;

namespace WpfApplication1
{
    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            MessageBox.Show("Password entered: " + passwordBox.Password,Title);
        }
    }
}

   
    
     


Multiple Subpaths with PathFigure

image_pdfimage_print


   
   
<Window  
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Class="SDKSample.SampleViewer"
    Title="  Examples" >

   <Canvas> 
          <Path Stroke="Black" StrokeThickness="1">
            <Path.Data>
              <PathGeometry>
                <PathGeometry.Figures>
                  <PathFigureCollection>
                    <PathFigure IsClosed="True" StartPoint="10,100">
                      <PathFigure.Segments>
                        <PathSegmentCollection>
                          <LineSegment Point="100,100" />
                          <LineSegment Point="100,50" />
                        </PathSegmentCollection>
                      </PathFigure.Segments>
                    </PathFigure>
                    <PathFigure IsClosed="True" StartPoint="10,10">
                      <PathFigure.Segments>
                        <PathSegmentCollection>
                          <LineSegment Point="100,10" />
                          <LineSegment Point="100,40" />
                        </PathSegmentCollection>
                      </PathFigure.Segments>
                    </PathFigure>                    
                  </PathFigureCollection>
                </PathGeometry.Figures>
              </PathGeometry>
            </Path.Data>
          </Path>
       
   </Canvas> 


</Window>

   
    
    
     


Close Path Command with PathFigure

image_pdfimage_print


   
   
<Window  
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Class="SDKSample.SampleViewer"
    Title="  Examples" >

   <Canvas> 
          <Path Stroke="Black" StrokeThickness="1">
            <Path.Data>
              <PathGeometry>
                <PathGeometry.Figures>
                  <PathFigureCollection>
                    <PathFigure IsClosed="True" StartPoint="10,100">
                      <PathFigure.Segments>
                        <PathSegmentCollection>
                          <LineSegment Point="100,100" />
                          <LineSegment Point="100,50" />
                        </PathSegmentCollection>
                      </PathFigure.Segments>
                    </PathFigure>
                  </PathFigureCollection>
                </PathGeometry.Figures>
              </PathGeometry>
            </Path.Data>
          </Path>
   </Canvas> 


</Window>

   
    
    
     


Drawn with a Path Shape with Geometry

image_pdfimage_print
   
   
<Window  
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Class="SDKSample.SampleViewer"
    Title="  Examples" >

   <Canvas> 
          <Path Stroke="Black" StrokeThickness="1" Fill="#CCCCFF">
            <Path.Data>
              <GeometryGroup>
                  <RectangleGeometry Rect="50,5 100,10" />
                  <RectangleGeometry Rect="5,5 95,180" />
                  <EllipseGeometry Center="100, 100" RadiusX="20" RadiusY="30"/>
                  <RectangleGeometry Rect="50,175 100,10" />
                  <PathGeometry>
                    <PathGeometry.Figures>
                      <PathFigureCollection>
                        <PathFigure IsClosed="true" StartPoint="50,50">
                          <PathFigure.Segments>
                            <PathSegmentCollection>
                              <BezierSegment Point1="75,300" Point2="125,100" Point3="150,50"/>
                              <BezierSegment Point1="125,300" Point2="75,100"  Point3="50,50"/>
                            </PathSegmentCollection>
                          </PathFigure.Segments>
                        </PathFigure>
                      </PathFigureCollection>
                    </PathGeometry.Figures>
                  </PathGeometry>               
              </GeometryGroup>
            </Path.Data>
          </Path>       
   </Canvas> 


</Window>