WPF RotateTransformed元素剪裁在窗口边界上 [英] WPF RotateTransformed element clipped on window bounds

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

问题描述

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

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



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






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






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


来源(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;
        }  
    }
}

推荐答案

请参阅我对该问题的评论。



问题听起来像你真的观察到了正确的行为;你想做什么取决于你的。如果行为是正确和可解释的,你不能只问任何想法?。这实际上取决于你想如何安排对象;而你没有分享你的要求。此外,如果您成功旋转了对象,则不清楚进行其他转换可能会出现什么问题。



此外,您的图片显示对象的一部分是被其他东西掩盖。找出它是什么:它可能是一些控制,或其他东西。首先,从窗口中删除除渲染对象以外的所有内容,或将其全部半透明。您将看到创建重叠的位置。再一次,答案取决于你想如何安排事情。



(顺便说一句,你的图像看起来不像你真的旋转。对象看起来有点倾斜。)



-SA
Please see my comment to the question.

The question sounds like you really observe correct behavior; and what you want to do about it depends on your. If the behavior is correct and explainable, you cannot just ask "any ideas?". It really depends on how you want to arrange the object; and you did not share your requirements. Besides, if you successfully rotated the object, it's unclear what could be a problem to do some other transformations.

Also, your picture shows that the part of your object is masked by something else. Find out what is it: it could be some control, or something else. To start with, remove everything from your window except the object you render, or make it all semi-transparent. You will see where you created the overlap. Again, the answer depends on how you want to arrange things.

(By the way, your image does not look like you really rotate. The object looks a bit skewed.)

—SA


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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆