Set border thickness


   
     

<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 BorderBrush="Black" BorderThickness="4px, 4px, 0px, 0px" 
                Margin="10">
            <TextBlock Text="A half border" />
        </Border>

    </UniformGrid>
</Window>

   
    
    
    
    
     


Border with LinearGradientBrush


   
    

<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">
  
    <Border Margin="0,10,0,10">
      <Border.Background>
        <LinearGradientBrush StartPoint="0,0.5" EndPoint="1,0.5">
          <LinearGradientBrush.GradientStops>
            <GradientStop Offset="0.0" Color="#CCCCFF" />
            <GradientStop Offset="1.0" Color="White" />
          </LinearGradientBrush.GradientStops>
        </LinearGradientBrush>
      </Border.Background>
    
    <TextBlock Margin="10" MaxWidth="700">
asdf
    </TextBlock>
    </Border>

</Window>

   
    
    
    
     


Adding border to TextBlock with Border


   
     
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      HorizontalAlignment="Center" VerticalAlignment="Center"
      TextElement.FontFamily="Palatino Linotype"
      FontSize="40">

    <Border BorderBrush="Black" BorderThickness="2" Width="213">
        <TextBlock TextTrimming="None" Text="Too much text." />
    </Border>

</Window>

   
    
    
    
    
     


Set Border Margin, BorderThickness, BorderBrush, Width and Height


   
     

<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="160" Width="300">
    <Grid>
        <Border Margin="8" 
                BorderThickness="1"
                BorderBrush="Black"
                Width="160" 
                Height="60">
            <TextBlock Foreground="DarkGray" 
                       VerticalAlignment="Center" 
                       HorizontalAlignment="Center"
                       ToolTip="This is a custom tooltip"
                       Text="Mouse Over for tooltip"/>
        </Border>
    </Grid>
    
</Window>

   
    
    
    
    
     


Set Border's BorderBrush to ImageBrush


   
     
<Page  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
   x:Class="Microsoft.Samples.Graphics.UsingImageBrush.TilingExample" >

  <Grid Margin="20">
    <Border Grid.Row="6" Grid.Column="4" BorderThickness="20" Width="200"
     HorizontalAlignment="Left">
      <Border.BorderBrush>
        <ImageBrush ImageSource="c:image.jpg" Viewport="-0.1,-0.1,1.5,1.5" />
      </Border.BorderBrush>
      <DockPanel>
        <TextBlock DockPanel.Dock="Top" TextWrapping="Wrap" Margin="10">This DockPanel has a border painted with an ImageBrush.</TextBlock>
      </DockPanel>
    </Border>

  </Grid>
</Page>

   
    
    
    
    
     


Simple Border


   
     

<Window x:Class="Content.SimpleBorder"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="SimpleBorder" Height="300" Width="300">
  <Border Margin="5" Padding="5" Background="LightYellow" 
          BorderBrush="SteelBlue" BorderThickness="3,5,3,5" CornerRadius="3"
          VerticalAlignment="Top">
    <StackPanel>
      <Button Margin="3">One</Button>
      <Button Margin="3">Two</Button>
      <Button Margin="3">Three</Button>
    </StackPanel>
  </Border>
</Window>

   
    
    
    
    
     


Create Indexed Bitmap

using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;

public class CreateIndexedBitmap : Window
{
[STAThread]
public static void Main()
{
Application app = new Application();
app.Run(new CreateIndexedBitmap());
}
public CreateIndexedBitmap()
{
List colors = new List();

for (int r = 0; r < 256; r += 17) for (int b = 0; b < 256; b += 17) colors.Add(Color.FromRgb((byte)r, 0, (byte)b)); BitmapPalette palette = new BitmapPalette(colors); byte[] array = new byte[256 * 256]; for (int x = 0; x < 256; x++) for (int y = 0; y < 256; y++) array[256 * y + x] = (byte)(((int)Math.Round(y / 17.0) << 4) | (int)Math.Round(x / 17.0)); BitmapSource bitmap = BitmapSource.Create(256, 256, 96, 96, PixelFormats.Indexed8,palette, array, 256); Image img = new Image(); img.Source = bitmap; Content = img; } } [/csharp]