如何更改Surface应用程序的应用程序方向

时间:2010-05-05 07:10:04

标签: wpf pixelsense

当用户按下按钮时,我需要在运行时将UI旋转180度的表面应用程序。我该怎么做呢?

1 个答案:

答案 0 :(得分:1)

只需在最顶层的面板上应用RotateTransform(我认为您甚至可以在实际的表面窗口上进行操作),角度为180度。

<s:SurfaceWindow x:Class="SurfaceApplication1.SurfaceWindow1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:s="http://schemas.microsoft.com/surface/2008"
    Title="SurfaceApplication1">
  <Grid>
    <Grid.LayoutTransform>
      <RotateTransform x:Name="mainOrientation"/>
    </Grid.LayoutTransform>
    <s:SurfaceButton Click="btn_Click" Content="Click to rotate" />   
    ... other content here ...
   </Grid>
</s:SurfaceWindow>

在代码背后:

private void btn_Click (object sender, RoutedEventArgs e)
{
    if (mainOrientation.Angle == 0)
        mainOrientation.Angle = 180;
    else
        mainOrientation.Angle = 0;
}

作为相关主题,您还可以收听表面的OrientationChanged event,以了解用户何时更改了应用的一面。一个好的做法是在发生这种情况时将应用程序转到正确的一边。

相关问题