Use a VisualBrush to magnify a portion of the screen.

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.UsingVisualBrush.MagnifyingGlassExample"
  Background="White">
  <Page.Resources>
    <Style TargetType="{x:Type Paragraph}">
      <Setter Property="Margin" Value="10" />
    </Style>
    <DrawingBrush x:Key="MyGridBackgroundBrushResource"
      Viewport="0,0,10,10" ViewportUnits="Absolute" TileMode="Tile">
      <DrawingBrush.Drawing>
        <DrawingGroup>
          <DrawingGroup.Children>
            <GeometryDrawing Brush="White">
              <GeometryDrawing.Geometry>
                <RectangleGeometry Rect="0,0,1,1" />
              </GeometryDrawing.Geometry>
            </GeometryDrawing>
            <GeometryDrawing Brush="#E6E8F6"
              Geometry="M 0,0 L 0,1 0.1,1 0.1,0.1 1,0.1 1,0 Z" />                      
          </DrawingGroup.Children>
        </DrawingGroup>
      </DrawingBrush.Drawing>
    </DrawingBrush>   
    
  </Page.Resources>

  <Grid>  
    <ScrollViewer>
      <StackPanel Name="magnifiedPanel" 
        VerticalAlignment="Stretch"
        MouseMove="updateMagnifyingGlass" 
        Background="{StaticResource MyGridBackgroundBrushResource}">
        
        <FlowDocumentScrollViewer>
        <FlowDocument>
<Paragraph><Button></Button></Paragraph>

<Paragraph><Border BorderBrush="Black" BorderThickness="1"><Image Source="c:image.jpg" Stretch="None" /></Border></Paragraph>

<Paragraph>this is a test</Paragraph> 
        </FlowDocument>
        </FlowDocumentScrollViewer>
      </StackPanel>
    </ScrollViewer>
    <Canvas Name="magnifyingGlassCanvas">
      <Ellipse Name="magnifyingGlassEllipse" Width="100" Height="100" Stroke="Black">
        <Ellipse.Fill>
          <DrawingBrush>
            <DrawingBrush.Drawing>
              <DrawingGroup>
                <DrawingGroup.Children>
                   <GeometryDrawing Brush="White">
                    <GeometryDrawing.Geometry>
                      <RectangleGeometry Rect="0,0,1,1" />
                    </GeometryDrawing.Geometry>
                  </GeometryDrawing>
                   <GeometryDrawing>
                    <GeometryDrawing.Brush>
                       <VisualBrush x:Name="myVisualBrush" ViewboxUnits="Absolute"
                        Visual="{Binding ElementName=magnifiedPanel}"/>
                    </GeometryDrawing.Brush>
                    <GeometryDrawing.Geometry>
                      <RectangleGeometry Rect="0,0,1,1" />
                    </GeometryDrawing.Geometry>
                  </GeometryDrawing>
                </DrawingGroup.Children>
              </DrawingGroup>
            </DrawingBrush.Drawing>
          </DrawingBrush>
        </Ellipse.Fill>
      </Ellipse>
    </Canvas>
  </Grid>
</Page>

//File:Window.xaml.cs
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Media;
using System.Windows.Input;

namespace Microsoft.Samples.Graphics.UsingVisualBrush
{
    public partial class MagnifyingGlassExample : Page
    {
        private static readonly double distanceFromMouse = 5;
        
        public MagnifyingGlassExample()
        {
        }
        private void updateMagnifyingGlass(object sender, MouseEventArgs args)
        {
            Mouse.SetCursor(Cursors.Cross);
            Point currentMousePosition = args.GetPosition(this);
            if (this.ActualWidth - currentMousePosition.X > magnifyingGlassEllipse.Width + distanceFromMouse)
            {
                Canvas.SetLeft(magnifyingGlassEllipse, currentMousePosition.X + distanceFromMouse);
            }
            else
            {
                Canvas.SetLeft(magnifyingGlassEllipse, currentMousePosition.X - distanceFromMouse - magnifyingGlassEllipse.Width);
            }
            
            if (this.ActualHeight - currentMousePosition.Y > magnifyingGlassEllipse.Height + distanceFromMouse)
            {
                Canvas.SetTop(magnifyingGlassEllipse, currentMousePosition.Y + distanceFromMouse);
            }
            else
            {
                Canvas.SetTop(magnifyingGlassEllipse, currentMousePosition.Y - distanceFromMouse - magnifyingGlassEllipse.Height);
            }
            myVisualBrush.Viewbox = new Rect(currentMousePosition.X - 10, currentMousePosition.Y  - 10, 20, 20);
        }
    }
}

   
    
     


Predefined brush in Brushes Class

image_pdfimage_print


   
  

<Window x:Class="WpfApplication1.SolidColorBrushExample"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  Title="SolidColorBrush Example" Height="415" Width="270">
  <Canvas Margin="5">
    <StackPanel>
      <TextBlock Margin="0,0,0,5">
        Predefined Brush in the Brushes class:
      </TextBlock>
      <Rectangle x:Name="rect1" Width="100" Height="30"
        Stroke="Blue" />

    </StackPanel>
  </Canvas>
</Window>
//File:Window.xaml.cs

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Shapes;


namespace WpfApplication1
{
    public partial class SolidColorBrushExample : Window
    {
        public SolidColorBrushExample()
        {
            InitializeComponent();
            SolidColorBrush brush = new SolidColorBrush();
            // Predefined brush in Brushes Class: 
            brush = Brushes.Red;
            rect1.Fill = brush;

        }

    }
}

   
    
     


Solid Color Brush In Code with predefined brush

image_pdfimage_print


   
  

<Window x:Class="WPFBrushes.SolidColorBrushInCode"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="WPFBrushes" Height="300" Width="300"
    >
    <Grid>
        
    </Grid>
</Window>
//File:Window.xaml.cs
using System.Windows;
using System.Windows.Documents;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;

namespace WPFBrushes
{
  public partial class SolidColorBrushInCode : System.Windows.Window
  {
    public SolidColorBrushInCode()
    {
      InitializeComponent();
      this.Width = 600;

      StackPanel sp = new StackPanel();
      sp.Margin = new Thickness(4.0);
      sp.HorizontalAlignment = HorizontalAlignment.Left;
      sp.Orientation = Orientation.Vertical;

      TextBlock tb1 = new TextBlock(new Run(@"Predefined Brush [ .Fill = Brushes.Red; ]"));
      Rectangle rect1 = new Rectangle();
      rect1.HorizontalAlignment = HorizontalAlignment.Left;
      rect1.Width = 60;
      rect1.Height = 20;
      rect1.Fill = Brushes.Red;

      sp.Children.Add(tb1);
      sp.Children.Add(rect1);

      this.Content = sp;

    }

  }
}

   
    
     


Solid Color Brush In Code with SolidColorBrush

image_pdfimage_print


   
  

<Window x:Class="WPFBrushes.SolidColorBrushInCode"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="WPFBrushes" Height="300" Width="300"
    >
    <Grid>
        
    </Grid>
</Window>
//File:Window.xaml.cs
using System.Windows;
using System.Windows.Documents;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;

namespace WPFBrushes
{
  public partial class SolidColorBrushInCode : System.Windows.Window
  {
    public SolidColorBrushInCode()
    {
      InitializeComponent();
      this.Width = 600;

      StackPanel sp = new StackPanel();
      sp.Margin = new Thickness(4.0);
      sp.HorizontalAlignment = HorizontalAlignment.Left;
      sp.Orientation = Orientation.Vertical;

      TextBlock tb1 = new TextBlock(new Run(@"Brush from Predefined Color [ .Fill = new SolidColorBrush(Colors.Green); ]"));
      Rectangle rect1 = new Rectangle();
      rect1.HorizontalAlignment = HorizontalAlignment.Left;
      rect1.Width = 60;
      rect1.Height = 20;
      rect1.Fill = new SolidColorBrush(Colors.Green);

      sp.Children.Add(tb1);
      sp.Children.Add(rect1);

      this.Content = sp;

    }

  }
}

   
    
     


Solid Color Brush In Code with SolidColorBrush and RGB color

image_pdfimage_print


   
  

<Window x:Class="WPFBrushes.SolidColorBrushInCode"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="WPFBrushes" Height="300" Width="300"
    >
    <Grid>
        
    </Grid>
</Window>
//File:Window.xaml.cs
using System.Windows;
using System.Windows.Documents;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;

namespace WPFBrushes
{
  public partial class SolidColorBrushInCode : System.Windows.Window
  {
    public SolidColorBrushInCode()
    {
      InitializeComponent();
      this.Width = 600;

      StackPanel sp = new StackPanel();
      sp.Margin = new Thickness(4.0);
      sp.HorizontalAlignment = HorizontalAlignment.Left;
      sp.Orientation = Orientation.Vertical;

      TextBlock tb1 = new TextBlock(new Run(@"Brush from RGB Color [ .Fill = new SolidColorBrush(Color.FromRgb(0, 0, 255)); ]"));
      Rectangle rect1 = new Rectangle();
      rect1.HorizontalAlignment = HorizontalAlignment.Left;
      rect1.Width = 60;
      rect1.Height = 20;
      rect1.Fill = new SolidColorBrush(Color.FromRgb(0, 0, 255));

      sp.Children.Add(tb1);
      sp.Children.Add(rect1);

      this.Content = sp;

    }

  }
}

   
    
     


Gradient background button

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="Nasty Button" Height="150" Width="550">
    <Grid Background="Black">
        <Button Margin="20" >
            <Button.Style>
                <Style TargetType="Button">
                    <Setter Property="Foreground">
                        <Setter.Value>
                            <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
                                <LinearGradientBrush.GradientStops>
                                    <GradientStop Offset="0.0" Color="Purple" />
                                    <GradientStop Offset="0.5" Color="Blue" />
                                    <GradientStop Offset="1.0" Color="Purple" />
                                </LinearGradientBrush.GradientStops>
                            </LinearGradientBrush>
                        </Setter.Value>
                    </Setter>
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="Button">
                                <Grid>
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="50" />
                                        <ColumnDefinition />
                                        <ColumnDefinition Width="50" />
                                    </Grid.ColumnDefinitions>
                                    <Grid.RowDefinitions>
                                        <RowDefinition MinHeight="50" />
                                    </Grid.RowDefinitions>
                     
                                    <Grid Grid.Column="1">
                                        <Rectangle RadiusX="10" RadiusY="10">
                                            <Rectangle.Fill>
                                                <RadialGradientBrush>
                                                    <RadialGradientBrush.GradientStops>
                                                        <GradientStop Offset="0.0" Color="Black" />
                                                        <GradientStop Offset="1.0" Color="Red" />
                                                    </RadialGradientBrush.GradientStops>
                                                </RadialGradientBrush>
                                            </Rectangle.Fill>
                                        </Rectangle>
                                        <ContentPresenter Margin="20,0,20,0" HorizontalAlignment="Center" VerticalAlignment="Center" />
                                    </Grid>
                    
                                </Grid>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </Button.Style>
        </Button>
    </Grid>
</Window>

   
    
    
    
    
    
     


Shaking Button

image_pdfimage_print


   
      

<StackPanel xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <StackPanel.Resources>
        <Style TargetType="{x:Type Button}">
            <Setter Property="HorizontalAlignment" Value="Center" />
            <Setter Property="Margin" Value="12" />
            <Setter Property="RenderTransformOrigin" Value="0.5 0.5" />
            <Setter Property="RenderTransform">
                <Setter.Value>
                    <RotateTransform />
                </Setter.Value>
            </Setter>
            <Style.Triggers>
                <EventTrigger RoutedEvent="Button.Click">
                    <BeginStoryboard>
                        <Storyboard TargetProperty="RenderTransform.Angle">
                            <DoubleAnimation 
                                From="-5" To="5" Duration="0:0:0.05" 
                                AutoReverse="True"
                                RepeatBehavior="3x"
                                FillBehavior="Stop" />
                        </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
            </Style.Triggers>
        </Style>
    </StackPanel.Resources>

    <Button>Click me to shake</Button>
</StackPanel>