加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 如何旋转WPF窗口?

发布时间:2020-12-15 08:17:15 所属栏目:百科 来源:网络整理
导读:是否可以使用xaml将 WPF窗口旋转45度? 解决方法 第一个问题:为什么要旋转整个窗口? 如果你真的需要它: 您无法旋转正常的WPF窗口.见:Rotate Window 您必须创建一个无边框窗口并为其提供UI.见:WPF Non-Client Area Design Techniques For Custom Window
是否可以使用xaml将 WPF窗口旋转45度?

解决方法

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

如果你真的需要它:

您无法旋转正常的WPF窗口.见:Rotate Window

您必须创建一个无边框窗口并为其提供UI.见:WPF Non-Client Area Design Techniques For Custom Window Frames

对于旋转窗口外观:

组:

> AllowTransparency属性
真正.
> WindowStyle为无
删除窗口铬
>背景
透明

包括边框(或任何有意义的东西,如矩形,圆形,椭圆等)作为窗口的内容和边框的以下属性:

>白色背景(或任何不透明的颜色)
>旋转变换,和
>更小的尺寸(以便在窗户内旋转时适合).

Border将为您的窗口提供UI.

注意创建自己的无边框窗口的cavaets,因为它要求你提供窗口界面,如最小化,最大化,关闭按钮;并且可能需要一些非托管代码.

此外,在下面的示例代码中,旋转时的边框必须保持在窗口的边界内,否则它(和您的自定义窗口)将被修剪.

示例代码

<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>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读