簡體   English   中英

如何在Windows Phone 8頁面中使用鎖定的方向更改一個組件的方向

[英]How to change orientation of one component in windows phone 8 page with locked orientation

我正在Windows Phone 8 / 8.1 C#/ XAML .NET 4.5應用程序上工作 ,我想知道如何更改頁面上一個控件/項目的方向(將其旋轉90度)。

我的肖像頁面上有一個webBrowser(保持鎖定在該方向),並且該Web瀏覽器需要處於橫向(並且不能旋轉)。

如何將網絡瀏覽器設置為旋轉90度並保持這種狀態?

因此,我想出了一種自行完成此操作的方法。

我將答案作為社區Wiki,以便以后來的任何人都可以編輯和添加更多選項來實現。

旋轉變換

選項之一是旋轉元素。

這是通過旋轉變換(答案組合從做這個答案這個問題)。

可以在后面的代碼中完成:

//Create a transformation
RotateTransform rt = new RotateTransform();
//and set the rotation angle
rt.Angle = 90; //number of degrees to rotate clockwise
               //for counterclockwise rotation use negative number

//default rotation is around top left corner of the control,
//but you sometimes want to rotate around the center of the control
//to do that, you need to set the RenderTransFormOrigin
//of the item you're going to rotate
//I did not test this approach, maybe You're going to need to use actual coordinates
//so this bit is for information purposes only
controlToRotate.RenderTransformOrigin = new Point(0.5,0.5);

//the name of the control is controlToRotate in this instance
controlToRotate.RenderTransform = rt;

或在XAML中:

  • 在這種情況下,瀏覽器是從我自己的代碼中提取的,並且所有內容都已設置好,以便旋轉項目並占據為其分配的完整位置

  • 瀏覽器在網格中,動態定位,網格被命名,以便我可以簡單地訪問它

  • 瀏覽器需要指定寬度和高度,在這種情況下,我將從網格的寬度和高度中獲取它,否則將以某種方式自動設置,結果以某種方式很小

  • 垂直和水平對齊方式設置為居中,從而使最終的旋轉也居中,否則不對齊(在動態布局中)

碼:

<Grid x:Name="ContentPanel">            
  <phone:WebBrowser x:Name="controlToRotate"
                    VerticalAlignment="Center"
                    HorizontalAlignment="Center"
                    RenderTransformOrigin=".5, .5"
                    Width="{Binding ElementName=ContentPanel, Path=ActualHeight}"
                    Height="{Binding ElementName=ContentPanel, Path=ActualWidth}">
    <phone:WebBrowser.RenderTransform>
      <RotateTransform Angle="90"/>
    </phone:WebBrowser.RenderTransform>
  </phone:WebBrowser>
</Grid>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM