WPF C# Tutorial

  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
  x:Class="Microsoft.Samples.Graphics.UsingVisualBrush.MagnifyingGlassExample"
  Background="White">
  
    
      
    
          Viewport="0,0,10,10" ViewportUnits="Absolute" TileMode="Tile">
      
        
          
            
              
                
              

            
                          Geometry="M 0,0 L 0,1 0.1,1 0.1,0.1 1,0.1 1,0 Z" />                      
          

        

      

       
    
  

    
    
              VerticalAlignment="Stretch"
        MouseMove="updateMagnifyingGlass" 
        Background="{StaticResource MyGridBackgroundBrushResource}">
        
        
        


this is a test 
        

        

      
    

    
      
        
          
            
              
                
                   
                    
                      
                    

                  
                   
                    
                                               Visual="{Binding ElementName=magnifiedPanel}"/>
                    

                    
                      
                    

                  

                

              

            

          

        

      
    
  


//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);
        }
    }
}