how do i set PageOrientation.Landscape in programmatically? Windows Phone 8 C#

北慕城南 提交于 2019-12-12 06:29:00

问题


i want to put fullscreen icon bar to play video in full screen,

for what i take application bar button :

private void BuildLocalizedApplicationBar()
        {
            // Set the page's ApplicationBar to a new instance of ApplicationBar.
            ApplicationBar = new ApplicationBar();

            // Create a new button and set the text value to the localized string from AppResources.
            ApplicationBarIconButton appBarButton = new ApplicationBarIconButton(new Uri("/images/AppbarIcon/wallpaper.png", UriKind.Relative));
            appBarButton.Text = "FullScreen";
            ApplicationBar.Buttons.Add(appBarButton);
            appBarButton.Click += appBarButton_Click;
        }

then i write click event to make it work : when we click, i want page as Landscape :, i am able to do using emulator right side button, but not able to do via code :

  void appBarButton_Click(object sender, EventArgs e)
            {
                //SupportedOrientations = SupportedPageOrientation.Landscape;
                this.Orientation = PageOrientation.Landscape;
            }

and when PageOrientation changed, i want to fire this event : it will be fire, when i doing from emulator right side button.

private void PhoneApplicationPage_OrientationChanged(object sender, OrientationChangedEventArgs e)
            {
                if (e.Orientation == PageOrientation.Landscape ||
                    e.Orientation == PageOrientation.LandscapeLeft ||
                    e.Orientation == PageOrientation.LandscapeRight)
                {
                    TitlePanel.Visibility = System.Windows.Visibility.Collapsed;

                    player.Height = Double.NaN;
                    player.Width = Double.NaN;

                    player.VerticalAlignment = System.Windows.VerticalAlignment.Stretch;
                    player.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;

                    SystemTray.IsVisible = false;

                }
                else
                {
                    TitlePanel.Visibility = System.Windows.Visibility.Visible;

                    player.Height = Double.NaN;
                    player.Width = Double.NaN;

                    player.VerticalAlignment = System.Windows.VerticalAlignment.Stretch;
                    player.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch;

                    SystemTray.IsVisible = true;
                }
            }

回答1:


This code will make your page landscape:

void appBarButton_Click(object sender, EventArgs e)
{
   this.SupportedOrientations = SupportedPageOrientation.Landscape;
   this.Orientation = PageOrientation.Landscape;
}


来源:https://stackoverflow.com/questions/23577709/how-do-i-set-pageorientation-landscape-in-programmatically-windows-phone-8-c-sh

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!