用户控件消失而不是在 RotateTransform 下转动

发布于 2024-08-04 08:01:36 字数 319 浏览 10 评论 0原文

我的 RotateTransform 行为有问题。
我在Grid内有一个用户控件,它旋转了-135°,但是当我将该形状移动到Grid的限制时,它开始消失,起作用就像它没有旋转一样。我该如何解决这个问题?

替代文本 http://img522.imageshack.us/img522/6241/cenask.jpg< /a>

I'm having problems with RotateTransform behavior.

I have a user control inside a Grid and it's rotated -135º, but when I move that shape to the limits of the Grid, it starts to disappear, acting like it has no rotation. How can I fix this?

alt text http://img522.imageshack.us/img522/6241/cenask.jpg

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

原来分手还会想你 2024-08-11 08:01:36

根据您的描述来看,我想说 UserControlGrid 的边界剪切,这是预期的默认行为。您可以在 Grid 上设置 ClipToBounds 属性,以确保在其外部运行的任何内容都不会被剪切。

例如,请考虑以下情况:

<Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="50"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="50"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="50"/>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="50"/>
        </Grid.ColumnDefinitions>

        <Grid Grid.Row="1" Grid.Column="1" ClipToBounds="True" Background="Blue">
            <Label Content="Testing a long label to see what happens" Background="Gray" RenderTransformOrigin=".5,.5">
                <Label.RenderTransform>
                    <RotateTransform Angle="-135"/>
                </Label.RenderTransform>
            </Label>
        </Grid>
    </Grid>
</Window>

这会导致:

alt text http://img514.imageshack .us/img514/8485/screenshotmf.png

ClipToBounds 更改为 true 会导致:

替代文本 http://img36.imageshack.us/img36/2682/screenshottz.png

Judging by your description, I'd say the UserControl is being clipped by the boundary of the Grid, which is the expected default behavior. You can set the ClipToBounds property on your Grid to ensure any content that runs outside of it is not clipped.

For example, consider the following:

<Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="50"/>
            <RowDefinition Height="*"/>
            <RowDefinition Height="50"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="50"/>
            <ColumnDefinition Width="*"/>
            <ColumnDefinition Width="50"/>
        </Grid.ColumnDefinitions>

        <Grid Grid.Row="1" Grid.Column="1" ClipToBounds="True" Background="Blue">
            <Label Content="Testing a long label to see what happens" Background="Gray" RenderTransformOrigin=".5,.5">
                <Label.RenderTransform>
                    <RotateTransform Angle="-135"/>
                </Label.RenderTransform>
            </Label>
        </Grid>
    </Grid>
</Window>

This results in:

alt text http://img514.imageshack.us/img514/8485/screenshotmf.png

Changing ClipToBounds to true results in:

alt text http://img36.imageshack.us/img36/2682/screenshottz.png

時窥 2024-08-11 08:01:36

这可能是旋转应用位置的问题。

RotateTransform 有两个属性(CenterX、CenterY),用于确定旋转的点。

我引用 MSDN

RotateTransform 的 CenterX 和 CenterY 属性指定对象旋转的点。该中心点在被变换的元素的坐标空间中表示。默认情况下,旋转应用于 (0,0),即要变换的对象的左上角。

下一个示例将 Polyline 对象绕点 (25,50) 顺时针旋转 45 度。

它有可能围绕对象的左上角旋转,如果这是设置在底层画布的左上角,那么它将在画布空间之外旋转。

希望这有帮助

It might be an issue with where the rotation is being applied.

There is two properties on a RotateTransform (CenterX, CenterY) that determines the point at which to rotate around.

I quote from MSDN

The CenterX and CenterY properties of the RotateTransform specify the point about which the object is rotated. This center point is expressed in the coordinate space of the element that is transformed. By default, the rotation is applied to (0,0), which is the upper-left corner of the object to transform.

The next example rotates a Polyline object clockwise 45 degrees about the point (25,50).

It's possible that it's rotating around the top left of your object, and if thats the set to the top left of the underlying canvas, then it will rotate outside of your canvas space.

Hope this helps

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文