Gradient brushes within a DrawingBrush. Two overlapping gradients are layered

image_pdfimage_print


   
      

<Window x:Class="Workspace.DockExample"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Workspace" Width="640" Height="480">
      <Rectangle Width="50" Height="50" Grid.Row="2" Grid.Column="1">
        <Rectangle.Fill>
          <DrawingBrush Viewport="0,0,1,1" TileMode="Tile">
            <DrawingBrush.Drawing>
              <DrawingGroup>
                <GeometryDrawing>
                  <GeometryDrawing.Geometry>
                    <RectangleGeometry Rect="0,0,1,1" />
                  </GeometryDrawing.Geometry>
                  <GeometryDrawing.Brush>
                    <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
                      <LinearGradientBrush.GradientStops>
                        <GradientStop Color="Blue" Offset="0.0" />
                        <GradientStop Color="#9966CC" Offset="0.5" />
                        <GradientStop Color="MediumBlue" Offset="1.0" />
                      </LinearGradientBrush.GradientStops>
                    </LinearGradientBrush>
                  </GeometryDrawing.Brush>
                </GeometryDrawing>
                <GeometryDrawing>
                  <GeometryDrawing.Geometry>
                    <RectangleGeometry Rect="0,0,1,1" />
                  </GeometryDrawing.Geometry>
                  <GeometryDrawing.Brush>
                    <RadialGradientBrush GradientOrigin="0.75,0.25">
                      <RadialGradientBrush.GradientStops>
                        <GradientStop Color="White" Offset="0.0" />
                        <GradientStop Color="Transparent" Offset="0.5" />
                        <GradientStop Color="Transparent" Offset="0.9" />
                        <GradientStop Color="Black" Offset="1.0" />
                      </RadialGradientBrush.GradientStops>
                    </RadialGradientBrush>
                  </GeometryDrawing.Brush>
                </GeometryDrawing>
              </DrawingGroup>
            </DrawingBrush.Drawing>
          </DrawingBrush>
        </Rectangle.Fill>
      </Rectangle>

</Window>

   
    
    
    
    
    
     


OpacityMask, LinearGradientBrush, RenderTransform

image_pdfimage_print
   
      
<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>

   
    
    
    
    
    
     


Brush resource

image_pdfimage_print


   
      


<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

image_pdfimage_print


   
   

<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&#91;1&#93;.Items&#91;2&#93;.Content.Length}" />
            <LineBreak />
            <Label Content="Number of characters in selected item = " />
            <Label Content="{Binding ElementName=page,Path=Content.Children&#91;1&#93;.SelectedItem.Content.Length}" />
        </TextBlock>
    </StackPanel>
</Page>

   
    
    
     


Bind ListBox ItemsSource to DayNames property of DateTimeFormatInfo

image_pdfimage_print


   
   

<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

image_pdfimage_print


   
   

<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

image_pdfimage_print


   
   

<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>