<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="Microsoft.Samples.Graphics.RectangleExample"
WindowTitle="Example">
<Canvas>
<Rectangle Grid.Row="1" RenderTransformOrigin="1,0.5">
<Rectangle.Fill>
<VisualBrush Visual="{Binding ElementName=txt}"></VisualBrush>
</Rectangle.Fill>
<Rectangle.OpacityMask>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientStop Offset="0.3" Color="Transparent"></GradientStop>
<GradientStop Offset="1" Color="#44000000"></GradientStop>
</LinearGradientBrush>
</Rectangle.OpacityMask>
<Rectangle.RenderTransform>
<ScaleTransform ScaleY="-1"></ScaleTransform>
</Rectangle.RenderTransform>
</Rectangle>
</Canvas>
</Page>
Author: coder
Brush resource
<Grid xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid.Resources>
<LinearGradientBrush x:Key="backgroundBrush" StartPoint="0,0" EndPoint="1,1">
<GradientStop Color="Blue" Offset="0"/>
<GradientStop Color="White" Offset="0.5"/>
<GradientStop Color="Red" Offset="1"/>
</LinearGradientBrush>
<SolidColorBrush x:Key="borderBrush">Red</SolidColorBrush>
</Grid.Resources>
<Grid.Background>
<StaticResource ResourceKey="backgroundBrush"/>
</Grid.Background>
<DockPanel>
<StackPanel DockPanel.Dock="Bottom" Orientation="Horizontal" HorizontalAlignment="Center">
<Button Background="{StaticResource backgroundBrush}" BorderBrush="{StaticResource borderBrush}" Margin="5">
<Image Height="21" Source="c:image.gif"/>
</Button>
</StackPanel>
<ListBox/>
</DockPanel>
</Grid>
Long Binding Path
<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"
FontSize="12pt"
Name="page">
<StackPanel>
<TextBlock HorizontalAlignment="Center">
First element in StackPanel
</TextBlock>
<ListBox HorizontalAlignment="Center"
Margin="24">
<ListBoxItem>First</ListBoxItem>
<ListBoxItem>Second</ListBoxItem>
<ListBoxItem>Third</ListBoxItem>
<ListBoxItem>Fourth</ListBoxItem>
<ListBoxItem>Fifth</ListBoxItem>
</ListBox>
<TextBlock HorizontalAlignment="Center">
<Label Content="Number of characters in third ListBox item = " />
<Label Content="{Binding ElementName=page, Path=Content.Children[1].Items[2].Content.Length}" />
<LineBreak />
<Label Content="Number of characters in selected item = " />
<Label Content="{Binding ElementName=page,Path=Content.Children[1].SelectedItem.Content.Length}" />
</TextBlock>
</StackPanel>
</Page>
Bind ListBox ItemsSource to DayNames property of DateTimeFormatInfo
<StackPanel xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:g="clr-namespace:System.Globalization;assembly=mscorlib">
<ListBox Name="lstbox"
HorizontalAlignment="Center"
Margin="24"
ItemsSource="{Binding
Source={x:Static g:DateTimeFormatInfo.CurrentInfo},
Path=DayNames,
Mode=OneTime}" />
</StackPanel>
Bind TextBlock Text to SelectedItem property of ListBox
<StackPanel xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:g="clr-namespace:System.Globalization;assembly=mscorlib">
<ListBox Name="lstbox"
HorizontalAlignment="Center"
Margin="24"
ItemsSource="{Binding
Source={x:Static g:DateTimeFormatInfo.CurrentInfo},
Path=DayNames,
Mode=OneTime}" />
<TextBlock HorizontalAlignment="Center"
Text="{Binding ElementName=lstbox,
Path=SelectedItem, Mode=OneWay}" />
</StackPanel>
Bind To TextBox Back and Forth
<Grid xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Label Grid.Row="0" Grid.Column="0"
Margin="24 24 24 0"
Content="Source TextBox Controls" />
<Label Grid.Row="0" Grid.Column="1"
Margin="24 24 24 0"
Content="Target TextBox Controls" />
<TextBox Grid.Row="1" Grid.Column="0" Name="txtbox1"
Margin="24" />
<TextBox Grid.Row="1" Grid.Column="1"
Margin="24"
Text="{Binding ElementName=txtbox1, Path=Text, Mode=TwoWay}" />
<TextBox Grid.Row="2" Grid.Column="0" Name="txtbox2"
Margin="24" />
<TextBox Grid.Row="2" Grid.Column="1"
Margin="24"
Text="{Binding ElementName=txtbox2, Path=Text, Mode=TwoWay}" />
<TextBox Grid.Row="3" Grid.Column="0" Name="txtbox3"
Margin="24" />
<TextBox Grid.Row="3" Grid.Column="1"
Margin="24"
Text="{Binding ElementName=txtbox3, Path=Text, Mode=TwoWay}" />
</Grid>
Binding FontFamily / FontSize value for current Control
<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 has a FontFamily of " />
<TextBlock Text="{Binding RelativeSource={RelativeSource self},Path=FontFamily}" />
<TextBlock Text=" and a FontSize of " />
<TextBlock Text="{Binding RelativeSource={RelativeSource self},Path=FontSize}" />
</StackPanel>
</StackPanel>