Bind RelativeSource's AncestorType

image_pdfimage_print


   
   
<StackPanel xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            TextBlock.FontSize="12" >
    <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
        <TextBlock Text="This TextBlock is inside a StackPanel with " />
        <TextBlock Text="{Binding RelativeSource={RelativeSource AncestorType={x:Type StackPanel}}, Path=Orientation}" />
        <TextBlock Text=" orientation" />
    </StackPanel>


</StackPanel>

   
    
    
     


Bind RelativeSource's AncestorType's Path

image_pdfimage_print


   
   


<StackPanel xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            TextBlock.FontSize="12" >
    <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
        <TextBlock Text="{Binding RelativeSource={RelativeSource AncestorType={x:Type StackPanel}, AncestorLevel=2},Path=Orientation}" />

    </StackPanel>



</StackPanel>

   
    
    
     


Bind Stroke Thickness to Slider

image_pdfimage_print


   
   

<StackPanel xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">


    <Polyline Margin="0.5in, 1.5in, 0, 0" 
              Points="0 0, 500 25, 0 50"
              VerticalAlignment="Center"
              Stroke="Blue"
              StrokeThickness="{Binding ElementName=sliderThickness,Path=Value }"
    />
    <Label Content="_Thickness" />
    <Slider Name="sliderThickness"
                    Minimum="0"
                    Maximum="100"
                    Value="24" />

</StackPanel>

   
    
    
     


Desktop to Control

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> 
        <Button Width="120" Height="20">
          <Button.Background>
            <LinearGradientBrush>
              <LinearGradientBrush.GradientStops>
                  <GradientStop Offset="0" Color="{x:Static SystemColors.DesktopColor}"/>
                  <GradientStop Offset="1" Color="{x:Static SystemColors.ControlColor}"/>
              </LinearGradientBrush.GradientStops>
            </LinearGradientBrush>
          </Button.Background>
        </Button> 

   </Canvas> 


</Window>

   
    
    
     


Bind Label To ScrollBar

image_pdfimage_print


   
   
<StackPanel xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <ScrollBar Name="scroll"
               Orientation="Horizontal" Margin="24" 
               Maximum="100" LargeChange="10" SmallChange="1" />

    <Label HorizontalAlignment="Center" 
           Content="{Binding ElementName=scroll, Path=Value}" />

</StackPanel>

   
    
    
     


Bind ScrollBar To Label

image_pdfimage_print


   
   

<StackPanel xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <ScrollBar Orientation="Horizontal" Margin="24" 
               Maximum="100" LargeChange="10" SmallChange="1"
               Value="{Binding ElementName=lbl, Path=Content}" />

    <Label Name="lbl" Content="50"
           HorizontalAlignment="Center" />

</StackPanel>