RotateTransformed元素剪裁在窗口边界上

RotateTransformed元素剪裁在窗口边界上

本文介绍了WPF RotateTransformed元素剪裁在窗口边界上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当RotateTransformed元素通过窗口的边界时,它的可见部分变得不可见。

保持此部分可见的任何想法?











来源(XAML):

When a RotateTransformed element passes the bounds of a window a visible part of it become invisible.
Any ideas to keep this part visible?

1.<img src="http://imageshack.us/a/img23/5608/z9em.png" width="250">



2.<img src="http://imageshack.us/a/img853/7248/0j3a.png" width="250">



3.<img src="http://img600.imageshack.us/img600/2885/p7he.png" width="250">

Source (XAML):

<Window x:Class="wpfRotateTransforClip.MainWindow"

        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

        Title="MainWindow" Height="350" Width="525" MouseMove="image1_MouseMove" MouseUp="image1_MouseUp" MouseDown="image1_MouseDown">
    <Grid ClipToBounds="False">
        <Image Height="96" HorizontalAlignment="Left" Margin="46,30,0,0" Name="image1" Stretch="Fill" VerticalAlignment="Top" Width="289" Source="/wpfRotateTransforClip;component/Images/1.png" MouseUp="image1_MouseUp" MouseDown="image1_MouseDown" MouseMove="image1_MouseMove" />
        <Slider Height="23" HorizontalAlignment="Left" Margin="116,228,0,0" Name="slider1" VerticalAlignment="Top" Width="252" Maximum="360" IsSnapToTickEnabled="True" ValueChanged="slider1_ValueChanged" />
        <Label Content="Label" Height="28" HorizontalAlignment="Left" Margin="179,257,0,0" Name="label1" VerticalAlignment="Top" Width="55" />
    </Grid>
</Window>


(C#):


(C#):

using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Effects;
namespace wpfRotateTransforClip
{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }
        Point p;
        bool moving=false;
        private void image1_MouseUp(object sender, MouseButtonEventArgs e)
        {
            moving = false;
        }
        private void image1_MouseDown(object sender, MouseButtonEventArgs e)
        {
            var pos = this.PointToScreen(Mouse.GetPosition(this));
            p = new Point(pos.X - image1.Margin.Left, pos.Y - image1.Margin.Top);
            moving = true;
        }
        private void image1_MouseMove(object sender, MouseEventArgs e)
        {
            if (!moving) return;
            Image ctrl = image1;
            var pos = this.PointToScreen(Mouse.GetPosition(this));
            ctrl.Margin = new Thickness(pos.X - p.X, pos.Y - p.Y, ctrl.Margin.Right, ctrl.Margin.Bottom);
        }
        private void slider1_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            if (image1 == null as Image) return;
            if (image1.RenderTransform as RotateTransform == null as RotateTransform)
            {
                RotateTransform tt = new RotateTransform();
                tt.CenterX = image1.Width / 2;
                tt.CenterY = image1.Height / 2;
                tt.Angle = (sender as Slider).Value;
                image1.RenderTransform = tt;
            }
            else
                (image1.RenderTransform as RotateTransform).Angle = (sender as Slider).Value;
            label1.Content = (sender as Slider).Value;
        }
    }
}

推荐答案


这篇关于WPF RotateTransformed元素剪裁在窗口边界上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 07:50