如何旋转一个WPF窗口? [英] How to rotate a WPF Window?

查看:212
本文介绍了如何旋转一个WPF窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能通过45度旋转的WPF窗口,使用XAML?

Is it possible to rotate a WPF Window by 45 degree, using xaml?

推荐答案

第一个问题:为什么要旋转整个窗口?

如果你真的需要它:
你不能旋转正常的WPF窗口。参见:<一href="http://social.msdn.microsoft.com/forums/en-US/wpf/thread/ce3317cd-b9b7-4260-ac44-308394458b92/"相对=nofollow>旋转窗

你将不得不建立一个无国界的窗口,并提供一个UI吧。请参阅: WPF非客户区设计技术自定义窗框

First question: Why do you want to rotate the whole window?

If you really need it:
You can't rotate the normal WPF window. See: Rotate Window

You will have to create a borderless window and provide a UI to it. See: WPF Non-Client Area Design Techniques For Custom Window Frames

对于旋转窗一看:
设置:

  • ALLOWTRANSPARENCY属性 真的。
  • WindowStyle到无以 删除窗口镶边
  • 背景 为透明
  • AllowTransparency property to true.
  • WindowStyle to None to remove window chrome
  • Background to Transparent

包括边框(或任何有意义的类似矩形,圆形,椭圆形等)窗口的内容和之后的边界的特性:

Include a border (or anything meaningful like rectangle, circle, ellipse, etc.) as content of the window and following properties of border:

  • 在白色背景(或任何非透明的颜色)
  • 旋转变换,以及
  • 更小的尺寸(从而当窗口内旋转,以适应)。

边框将提供用户界面的窗口。

Border will provide the UI to your window.


注意创造自己的无边框窗口cavaets的,因为它需要你提供像最小化,最大化,关闭按钮的窗口界面;并且可能需要一些非托管的code。
另外,在下面样品code,在旋转时的边界必须保持的窗口的范围内,否则(和自定义窗口)将被修整。


Be aware of cavaets of creating own borderless window, as it requires you to provide the window interface like minimise, maximise, close buttons; and may require some unmanaged code.
Also, in sample code below, the border when rotated has to be kept within the bounds of the window, otherwise it (and your custom window) will be trimmed.

样品code

<Window x:Class="CustomWindowStyle.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        AllowsTransparency="True" WindowStyle="None" Background="Transparent"
        Title="MainWindow" Height="600" Width="600">

        <Border BorderBrush="Green" BorderThickness="2" Background="White" Width="360" Height="360">
            <Border.RenderTransform>
                <RotateTransform Angle="-45" CenterX="180" CenterY="180"/>
            </Border.RenderTransform>
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="23" />
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>
                <Button Grid.Row="0" Content="X" Height="23" Width="23" Name="button1" HorizontalAlignment="Right" VerticalAlignment="Top" Click="button1_Click"/>
                <Grid Grid.Row="1">
                    <!--Main window content goes here-->
                    <TextBlock Text="Main window content goes here" HorizontalAlignment="Center" />
                </Grid>
            </Grid>
        </Border>
</Window>

这篇关于如何旋转一个WPF窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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