Set border corner radius

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="300" Width="300">
    <UniformGrid>
        <UniformGrid.Resources>
            <Style TargetType="{x:Type TextBlock}">
                <Setter Property="FontSize" Value="14" />
                <Setter Property="HorizontalAlignment" Value="Center" />
                <Setter Property="VerticalAlignment" Value="Center" />
            </Style>
        </UniformGrid.Resources>

        <Border CornerRadius="15" BorderBrush="Black" 
                BorderThickness="2px, 5px, 2px, 5px" Margin="10">
            <TextBlock Text="A rounded border" />
        </Border>


    </UniformGrid>
</Window>

   
    
    
    
    
     


Display a Border

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="300" Width="300">
    <UniformGrid>
        <UniformGrid.Resources>
            <Style TargetType="{x:Type TextBlock}">
                <Setter Property="FontSize" Value="14" />
                <Setter Property="HorizontalAlignment" Value="Center" />
                <Setter Property="VerticalAlignment" Value="Center" />
            </Style>
        </UniformGrid.Resources>
        <Border CornerRadius="90" Background="LightBlue" BorderThickness="2px"
                Margin="10">
            <TextBlock Text="A circular border" />
        </Border>
    </UniformGrid>
</Window>

   
    
    
    
    
     


A custom pen to draw the borders

image_pdfimage_print


   
      

<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
        xmlns:sys="clr-namespace:System;assembly=mscorlib" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >
  <Image>
  <Image.Source>
    <DrawingImage>
      <DrawingImage.Drawing>

        <DrawingGroup>
          <GeometryDrawing>
            <GeometryDrawing.Geometry>
              <GeometryGroup>
                <RectangleGeometry Rect="01,0,20,20" />
                <RectangleGeometry Rect="1160,120,20,20" />
                <EllipseGeometry Center="715,75" RadiusX="50" RadiusY="50" />
                <LineGeometry StartPoint="75,75" EndPoint="180,0" />
              </GeometryGroup>
            </GeometryDrawing.Geometry>
            <GeometryDrawing.Pen>
             <Pen Thickness="10" LineJoin="Round"
                      EndLineCap="Triangle" StartLineCap="Round" DashStyle = "{x:Static DashStyles.DashDotDot}" >
               <Pen.Brush>
                 <LinearGradientBrush>
                   <GradientStop Offset="0.0" Color="Red" />
                   <GradientStop Offset="1.0" Color="Green" />
                 </LinearGradientBrush>
                </Pen.Brush>
              </Pen>
            </GeometryDrawing.Pen>

          </GeometryDrawing>
        </DrawingGroup>
      </DrawingImage.Drawing>
    </DrawingImage>
  </Image.Source>
 </Image>
</Window>

   
    
    
    
    
    
     


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>