Dynamic Clipping : Clip « Windows Presentation Foundation « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Design Patterns
8.Development Class
9.Event
10.File Stream
11.Generics
12.GUI Windows Form
13.Language Basics
14.LINQ
15.Network
16.Office
17.Reflection
18.Regular Expressions
19.Security
20.Services Event
21.Thread
22.Web Services
23.Windows
24.Windows Presentation Foundation
25.XML
26.XML LINQ
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source
C# / C Sharp » Windows Presentation Foundation » ClipScreenshots 
Dynamic Clipping
Dynamic Clipping
  
<StackPanel xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  xmlns:d="http://schemas.microsoft.com/expression/interactivedesigner/2006"
  mc:Ignorable="d"
  x:Class="PaintDrawExamples.DynamicClipping" 
  Width="640" Height="480">

    <StackPanel.Resources>
        <Storyboard x:Key="OnLoaded"/>
    </StackPanel.Resources>
    <StackPanel.Triggers>
        <EventTrigger RoutedEvent="FrameworkElement.Loaded">
            <BeginStoryboard x:Name="OnLoaded_BeginStoryboard" Storyboard="{DynamicResource OnLoaded}"/>
        </EventTrigger>
    </StackPanel.Triggers>
    <Canvas Height="100" x:Name="Canvas" Width="436">
        <Canvas.Clip>
            <PathGeometry>
                <PathFigure StartPoint="1,5" IsClosed="True" IsFilled="True">
                    <BezierSegment IsSmoothJoin="True" Point1="2,2" Point2="26,1" Point3="24,127" IsStroked="True"/>
                    <BezierSegment IsSmoothJoin="True" Point1="1,1" Point2="14,9" Point3="19,5" IsStroked="True"/>
                    <BezierSegment IsSmoothJoin="True" Point1="14,11" Point2="18,-22.5" Point3="24,-2" IsStroked="True"/>
                    <BezierSegment IsSmoothJoin="True" Point1="26,-200" Point2="29,1" Point3="300,5" IsStroked="True"/>
                </PathFigure>
            </PathGeometry>
        </Canvas.Clip>
        <Rectangle d:LayoutOverrides="Height" Stroke="{x:Null}" Fill="Red" Width="436" Height="100" x:Name="Rectangle" Canvas.Left="0" Canvas.Top="0"/>
        <Label Background="Black" x:Name="Label" Content="This is my clipped space." Canvas.Left="46" Canvas.Top="26" d:IsHidden="True"/>
    </Canvas>
</StackPanel>
//File:Window.xaml.cs

using System;
using System.IO;
using System.Net;
using System.Windows;
using System.Windows.Input;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Navigation;

namespace PaintDrawExamples
{
    public partial class DynamicClipping
    {
        public DynamicClipping()
        {
            this.InitializeComponent();
            this.Canvas.VerticalAlignment = VerticalAlignment.Center;
            this.Canvas.HorizontalAlignment = HorizontalAlignment.Center;

            CompositionTarget.Rendering += CompositionTarget_Rendering;
        }

        private void CompositionTarget_Rendering(object sender, EventArgs e)
        {
            Point mousePos = Mouse.GetPosition(this.Canvas);
            Geometry clippingRegion = this.Canvas.Clip;

            TranslateTransform newPos = new TranslateTransform();
            newPos.X = mousePos.X - (this.Canvas.Width / 2);
            newPos.Y = mousePos.Y - (this.Canvas.Height / 2);

            clippingRegion.Transform = newPos;
        }
    }
}

   
    
  
Related examples in the same category
1.Clipped ButtonClipped Button
2.ClippingClipping
3.Clipping With ViewboxClipping With Viewbox
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.