2011-04-19 127 views

回答

7

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

如果你真的需要它:
您不能转动正常的WPF窗口。请参阅:Rotate Window

您将不得不创建无边框窗口并为其提供UI。请参阅:WPF Non-Client Area Design Techniques For Custom Window Frames

对于旋转窗一看:
集:

  • ALLOWTRANSPARENCY属性 真。
  • WindowStyle为无给 删除窗口铬
  • 背景 到透明

包含一个边界(或任何有意义象矩形,圆,椭圆等)的窗口的内容和以下性质边界:

  • 白色背景(或任何非透明色)
  • 旋转变换,和
  • 较小的尺寸(以便在窗口内旋转时适合)。

边框将为您的窗口提供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> 
+1

谢谢,我想给用户控件以交互方式旋转窗口,让应用更有趣。这是一个像应用程序的游戏,所以想要根据窗口方向来控制重力,我知道这很愚蠢,但这就是想法。 – 2011-04-19 16:35:12

+2

我有一个预感,它一定是一些像游戏一样的游戏。 :)无论如何,想添加(虽然隐含):1。边界可以用任何有意义的例如椭圆形,圆形等等,2.对于边框背景不一定必须是白色的 - 它可以是任何不透明的颜色。 – publicgk 2011-04-19 22:27:15