2011-04-19 59 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