如何在Windows Phone 7上使用屏幕方向来显示文本?

时间:2012-06-26 18:17:21

标签: windows-phone-7 windows-phone-7.1 screen-orientation

我正在学习如何使用“支持的方向”来更改文本块中的值或文本。我想要的是当设备倾斜到横向模式时,文本块应显示“再见”,当它倾斜到纵向模式时,它应该说“欢迎”

我想知道在if()语句中应该使用什么关系运算符,以便它给出正确的输出。

我应该在if()内使用什么?

  1. if(Orientation.Equals(SupportedOrientation.Portrait)) { // display "Welcome"}
  2. if(SupportedOrientation.Equals(SupportedPageOrientation.Portrait)) {// display "Welcome"}
  3. 如何使用方向更改我想要的任何值?

1 个答案:

答案 0 :(得分:1)

您可以使用PhoneApplicationPage类的OrientationChanged事件,或者如果您在页面类中编写代码,则覆盖OnOrientationChanged方法。

this.OrientationChanged += new EventHandler<OrientationChangedEventArgs>(MainPage_Orientationchanged)

void MainPage_OrientationChanged(object sender, OrientationChangedEventArgs e)

  {
     if (orientation == PageOrientation.LandscapeLeft ||
     orientation == PageOrientation.LandscapeRight)

  {

    textblock.text = bye;

  }

if (orientation == PageOrientation.PortraitLeft ||
     orientation == PageOrientation.PortraitRight)

{

    textblock.text = welcome;
}

 }