Change border

image_pdfimage_print


   
  
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        x:Class="AboutDialog" MouseRightButtonDown="AboutDialog_MouseRightButtonDown"
        Title="About WPF Unleashed" SizeToContent="WidthAndHeight"
        Background="OrangeRed">
  <StackPanel>
    <Label FontWeight="Bold" FontSize="20" Foreground="White">
      WPF
    </Label>
    <Label>License</Label>
    <Label>Installed Dll:</Label>
    <ListBox>
      <ListBoxItem>1</ListBoxItem>
      <ListBoxItem>2</ListBoxItem>
      <ListBoxItem>3</ListBoxItem>
      <ListBoxItem>4</ListBoxItem>
      <ListBoxItem>5</ListBoxItem>
      <ListBoxItem>6</ListBoxItem>
      <ListBoxItem>7</ListBoxItem>
      <ListBoxItem>8</ListBoxItem>
      <ListBoxItem>9</ListBoxItem>
      
    </ListBox>
    <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
      <Button MinWidth="75" Margin="10">Help</Button>
      <Button MinWidth="75" Margin="10">OK</Button>
    </StackPanel>
    <StatusBar>test</StatusBar>
  </StackPanel>
</Window>
//File:Window.xaml.cs
using System;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Controls;

public partial class AboutDialog : Window
{
    public AboutDialog()
    {
        InitializeComponent();
    }

    void AboutDialog_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
    {
        Console.WriteLine("Source = " + e.Source.GetType().Name);
        Console.WriteLine("OriginalSource = " + e.OriginalSource.GetType().Name + " @ " + e.Timestamp);
        Control source = e.Source as Control;
        if (source.BorderThickness != new Thickness(5))
        {
            source.BorderThickness = new Thickness(5);
            source.BorderBrush = Brushes.Black;
        }
        else
            source.BorderThickness = new Thickness(0);
    }
}

   
    
     


Set color for SolidColorBrush

image_pdfimage_print


   
      


<Window x:Class="WPFBrushes.ColorAndAlpha"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  Title="Alpha Channel" Height="300" Width="300">
    <Grid VerticalAlignment="Center" HorizontalAlignment="Center">

        <Rectangle Height="50" Width="50" Stroke="Black" StrokeThickness="4" Margin="4">
            <Rectangle.Fill>
                <SolidColorBrush>
                    <SolidColorBrush.Color>
                        <Color A="0" R="111" G="110" B="0"/>
                    </SolidColorBrush.Color>
                </SolidColorBrush>
            </Rectangle.Fill>
        </Rectangle>
    </Grid>
</Window>

   
    
    
    
    
    
     


Paint with system brushes and colors.

image_pdfimage_print


   
      

<Window  
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Class="SystemColorsAndBrushes_markup.Window1"
    Title="System Colors" >
   <Window.Resources>
    <Style TargetType="{x:Type Rectangle}">
      <Setter Property="Margin" Value="10,0,10,0"/>
      <Setter Property="HorizontalAlignment" Value="Left"/>
      <Setter Property="Height" Value="20"/>
      <Setter Property="Width" Value="120"/>
      <Setter Property="Stroke" Value="Black"/>
      <Setter Property="StrokeThickness" Value="1"/>
    </Style>
    <Style TargetType="{x:Type TextBlock}">
      <Setter Property="Margin" Value="10,20,10,0"/>
    </Style>
    <Style TargetType="{x:Type Button}">
      <Setter Property="Margin" Value="10,0,10,0"/>
      <Setter Property="HorizontalAlignment" Value="Left"/>
    </Style>
    </Window.Resources>
    <StackPanel Background="White">
        <TextBlock>ActiveBorder</TextBlock>
        <Rectangle Fill="{x:Static SystemColors.ActiveBorderBrush}" />
        
        <TextBlock>ActiveCaption</TextBlock>
        <Rectangle Fill="{x:Static SystemColors.ActiveCaptionBrush}" />
        
        <TextBlock>ActiveCaptionText</TextBlock>
        <Rectangle Fill="{x:Static SystemColors.ActiveCaptionTextBrush}" />
        
        <TextBlock>AppWorkspace</TextBlock>
        <Rectangle Fill="{x:Static SystemColors.AppWorkspaceBrush}" />
        
        <TextBlock>Control</TextBlock>
        <Rectangle Fill="{x:Static SystemColors.ControlBrush}" />
        
        <TextBlock>ControlDark</TextBlock>
        <Rectangle Fill="{x:Static SystemColors.ControlDarkBrush}" />
        
        <TextBlock>ControlDarkDark</TextBlock>
        <Rectangle Fill="{x:Static SystemColors.ControlDarkDarkBrush}" />
        
        <TextBlock>ControlLight</TextBlock>
        <Rectangle Fill="{x:Static SystemColors.ControlLightBrush}" />
        
        <TextBlock>ControlLightLight</TextBlock>
        <Rectangle Fill="{x:Static SystemColors.ControlLightLightBrush}" />
        
        <TextBlock>ControlText</TextBlock>
        <Rectangle Fill="{x:Static SystemColors.ControlTextBrush}" />
        
        <TextBlock>Desktop</TextBlock>
        <Rectangle Fill="{x:Static SystemColors.DesktopBrush}" />
        
        <TextBlock>GradientActiveCaption</TextBlock>
        <Rectangle Fill="{x:Static SystemColors.GradientActiveCaptionBrush}" />
        
        <TextBlock>GradientInactiveCaption</TextBlock>
        <Rectangle Fill="{x:Static SystemColors.GradientInactiveCaptionBrush}" />
        
        <TextBlock>GrayText</TextBlock>
        <Rectangle Fill="{x:Static SystemColors.GrayTextBrush}" />
        
        <TextBlock>Highlight</TextBlock>
        <Rectangle Fill="{x:Static SystemColors.HighlightBrush}" />
        
        <TextBlock>HighlightText</TextBlock>
        <Rectangle Fill="{x:Static SystemColors.HighlightTextBrush}" />
        
        <TextBlock>HotTrack</TextBlock>
        <Rectangle Fill="{x:Static SystemColors.HotTrackBrush}" />
        
        <TextBlock>InactiveBorder</TextBlock>
        <Rectangle Fill="{x:Static SystemColors.InactiveBorderBrush}" />
        
        <TextBlock>InactiveCaption</TextBlock>
        <Rectangle Fill="{x:Static SystemColors.InactiveCaptionBrush}" />
        
        <TextBlock>InactiveCaptionText</TextBlock>
        <Rectangle Fill="{x:Static SystemColors.InactiveCaptionTextBrush}" />
        
        <TextBlock>Info</TextBlock>
        <Rectangle Fill="{x:Static SystemColors.InfoBrush}" />
        
        <TextBlock>InfoText</TextBlock>
        <Rectangle Fill="{x:Static SystemColors.InfoTextBrush}" />
        
        <TextBlock>Menu</TextBlock>
        <Rectangle Fill="{x:Static SystemColors.MenuBrush}" />
        
        <TextBlock>MenuBar</TextBlock>
        <Rectangle Fill="{x:Static SystemColors.MenuBarBrush}" />
        
        <TextBlock>MenuHighlight</TextBlock>
        <Rectangle Fill="{x:Static SystemColors.MenuHighlightBrush}" />
        
        <TextBlock>MenuText</TextBlock>
        <Rectangle Fill="{x:Static SystemColors.MenuTextBrush}" />
        
        <TextBlock>ScrollBar</TextBlock>
        <Rectangle Fill="{x:Static SystemColors.ScrollBarBrush}" />
        
        <TextBlock>Window</TextBlock>
        <Rectangle Fill="{x:Static SystemColors.WindowBrush}" />
        
        <TextBlock>WindowFrame</TextBlock>
        <Button Width="120" Height="20" Background="{x:Static SystemColors.WindowFrameBrush}" />
        
        <TextBlock>WindowText</TextBlock>
        <Button Width="120" Height="20" Background="{x:Static SystemColors.WindowTextBrush}" />
      </StackPanel> 

  
</Window>

   
    
    
    
    
    
     


Uses a predefined SolidColorBrush, defined by the System.Windows.Media.Brushes class

image_pdfimage_print


   
      
            
<Window x:Class="WpfApplication1.ShapesWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="ShapesWindow" Height="160" Width="400">
  <Window.Resources>
    <Style TargetType="{x:Type Rectangle}">
      
      <!-- Gives all the rectangles in this panel a white stroke. -->
      <Setter Property="Stroke" Value="White"/>
      <Setter Property="StrokeThickness" Value="1"/>
    </Style>
  </Window.Resources>
    <Canvas>


      <Rectangle Width="50" Height="50" Fill="Blue" />
    </Canvas>
</Window>

   
    
    
    
    
    
     


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>