A rectangle with a rotate transformation


   
     
<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" >
  <Grid>

    <Rectangle Height ="100" Width ="40" Fill ="Red" Grid.Row="0" Grid.Column="0">
      <Rectangle.LayoutTransform>
        <RotateTransform Angle ="45"/>
      </Rectangle.LayoutTransform>
    </Rectangle>

  </Grid>

</Window>

   
    
    
    
    
     


Trigger animation with Rectangle.MouseEnter


   
     
<Window x:Class="Main"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  Title="" Height="300" Width="300">
  <Grid>
    <Rectangle Height="100" Width="100" Fill="Firebrick" Stroke="Black" StrokeThickness="1">
      <Rectangle.Style>
        <Style TargetType="Rectangle">
          <Style.Triggers>
            <EventTrigger RoutedEvent="Rectangle.MouseEnter">
              <BeginStoryboard>
                <Storyboard>
                  <ParallelTimeline RepeatBehavior="Forever" AutoReverse="True">
                    <DoubleAnimation Storyboard.TargetProperty="Width" To="150" />
                    <DoubleAnimation Storyboard.TargetProperty="Height" To="150" />
                    <ColorAnimation Storyboard.TargetProperty="Fill.Color" To="Orange" />
                  </ParallelTimeline>
                </Storyboard>
              </BeginStoryboard>
            </EventTrigger>
          </Style.Triggers>
        </Style>
      </Rectangle.Style>
    </Rectangle>
  </Grid>
</Window>

   
    
    
    
    
     


Trigger animation with Rectangle.MouseLeave


   
     
<Window x:Class="Main"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  Title="" Height="300" Width="300">
  <Grid>
    <Rectangle Height="100" Width="100" Fill="Firebrick" Stroke="Black" StrokeThickness="1">
      <Rectangle.Style>
        <Style TargetType="Rectangle">
          <Style.Triggers>
            <EventTrigger RoutedEvent="Rectangle.MouseLeave">
              <BeginStoryboard>
                <Storyboard>
                  <ParallelTimeline>
                    <DoubleAnimation Storyboard.TargetProperty="Width" To="100" />
                    <DoubleAnimation Storyboard.TargetProperty="Height" To="100" />
                    <ColorAnimation Storyboard.TargetProperty="Fill.Color" To="Red" />
                  </ParallelTimeline>
                </Storyboard>
              </BeginStoryboard>
            </EventTrigger>
          </Style.Triggers>
        </Style>
      </Rectangle.Style>
    </Rectangle>
  </Grid>
</Window>

   
    
    
    
    
     


Rectangle.Fill with 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">

    <Rectangle
      Grid.Row="3" Grid.Column="0"
      Width="300" Height="150"
      Stroke="MediumBlue" StrokeThickness="1"
      HorizontalAlignment="Left">
      <Rectangle.Fill>
        <ImageBrush Stretch="None"  ImageSource="c:image.jpg"  />
      </Rectangle.Fill>
    </Rectangle>

  </Grid>
</Page>

   
    
    
    
    
    
     


PresentationTraceSources.SetTraceLevel(binding,PresentationTraceLevel.High);


   
  

<Window x:Class="WpfApplication1.Monitor"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:diag="clr-namespace:System.Diagnostics;assembly=System"
    xmlns:debug="clr-namespace:System.Diagnostics;assembly=WindowsBase"
    Title="Monitor" Height="400" Width="400">
    <Grid>
        <ListView Name="listView1">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <WrapPanel>
                        <TextBlock Text="{Binding Path=Id}" MinWidth="80" />
                        <TextBlock Text="{Binding Path=ProcessName}" MinWidth="180" />
                        <TextBlock>
                                <TextBlock.Text>
                                    <Binding Path="WorkingSet" />
                                </TextBlock.Text>
                        </TextBlock>
                    </WrapPanel>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </Grid>
</Window>



//File:Window.xaml.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Diagnostics;

namespace WpfApplication1
{
    public partial class Monitor : Window
    {
        public Monitor()
        {
            InitializeComponent();
            BindProcessesToListView();
        }

        private void BindProcessesToListView()
        {
            ObjectDataProvider provider = new ObjectDataProvider();
            provider.ObjectType = typeof(Process);
            provider.MethodName = "GetProcesses";
            Binding binding = new Binding();
            binding.Source = provider;
            binding.Mode = BindingMode.OneWay;
            PresentationTraceSources.SetTraceLevel(binding,PresentationTraceLevel.High);
            listView1.SetBinding(ListView.ItemsSourceProperty, binding);
        }
    }
}

   
    
     


Print Custom Page


   
  
<Window x:Class="Printing.PrintCustomPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="PrintCustomPage" Height="300" Width="300">
    <StackPanel>
      <TextBox Name="txtContent" Margin="3" TextWrapping="Wrap" VerticalScrollBarVisibility="Visible">
        this is a test
      </TextBox>
      <Button Grid.Row="1" Margin="3" Padding="5" Click="cmdPrint_Click" VerticalAlignment="Top">Print</Button>
    </StackPanel>
</Window>
//File:Window.xaml.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Globalization;

namespace Printing
{
    public partial class PrintCustomPage : System.Windows.Window
    {
        public PrintCustomPage()
        {
            InitializeComponent();
        }
        private void cmdPrint_Click(object sender, RoutedEventArgs e)
        {           
            PrintDialog printDialog = new PrintDialog();
            if (printDialog.ShowDialog() == true)
            {
                DrawingVisual visual = new DrawingVisual();
                using (DrawingContext dc = visual.RenderOpen())
                {
                    FormattedText text = new FormattedText(txtContent.Text,
                        CultureInfo.CurrentCulture, FlowDirection.LeftToRight,
                        new Typeface("Calibri"), 20, Brushes.Black);

                    text.MaxTextWidth = printDialog.PrintableAreaWidth / 2;
                    Point point = new Point(100,100);

                    dc.DrawText(text, point);

                    dc.DrawRectangle(null, new Pen(Brushes.Black, 1),
                        new Rect(200, 200, 50,50));
                }

                printDialog.PrintVisual(visual, "A Custom-Printed Page");
            }
        }
    }
}

   
    
     


Print Scaled Visual


   
  
<Window x:Class="Printing.PrintScaledVisual"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="PrintScaledVisual" Height="184" Width="269">
  <StackPanel>
    <Button Click="cmdPrint_Click">Print</Button>
  </StackPanel>
</Window>

//File:Window.xaml.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Printing
{
    public partial class PrintScaledVisual : System.Windows.Window
    {
        public PrintScaledVisual()
        {
            InitializeComponent();
        }

        private void cmdPrint_Click(object sender, RoutedEventArgs e)
        {
            PrintDialog printDialog = new PrintDialog();
            if (printDialog.ShowDialog() == true)
            {
                Run run = new Run("This is a test.");
                TextBlock visual = new TextBlock(run);                
                visual.Margin = new Thickness(15);
                visual.TextWrapping = TextWrapping.Wrap;

                double zoom = 2;
                visual.LayoutTransform = new ScaleTransform(zoom / 100, zoom / 100);
                Size pageSize = new Size(printDialog.PrintableAreaWidth, printDialog.PrintableAreaHeight);
                visual.Measure(pageSize);
                visual.Arrange(new Rect(0, 0, pageSize.Width, pageSize.Height));
                printDialog.PrintVisual(visual, "A Scaled Drawing");
            }
        }
    }
}