コード例 #1
0
        private void SyncViewWithOrientation()
        {
            var appView = ApplicationView.GetForCurrentView();

#if WINDOWS_PHONE_APP
            appView.SetDesiredBoundsMode(Windows.UI.ViewManagement.ApplicationViewBoundsMode.UseCoreWindow);

            if (appView.Orientation == ApplicationViewOrientation.Landscape)
            {
                BottomAppBar.Closed    += BottomAppBar_IsOpenChanged;
                BottomAppBar.Opened    += BottomAppBar_IsOpenChanged;
                BottomAppBar.Opacity    = 0;
                BottomAppBar.Visibility = Visibility.Collapsed;
                AppBarHint.Visibility   = Visibility.Visible;
                LastReadSection.Margin  = new Thickness(0, -60, 0, 0);
                var logo = VisualTreeHelperExtensions.GetDescendantsOfType <Canvas>(RootHub).FirstOrDefault(elem => elem.Name == "Logo");
                if (logo != null)
                {
                    (logo.RenderTransform as TranslateTransform).X = LastReadSection.ActualWidth;
                }
            }
            else
            {
                BottomAppBar.Closed    -= BottomAppBar_IsOpenChanged;
                BottomAppBar.Opened    -= BottomAppBar_IsOpenChanged;
                BottomAppBar.Opacity    = 1;
                BottomAppBar.Visibility = Visibility.Visible;
                AppBarHint.Visibility   = Visibility.Collapsed;
                LastReadSection.Margin  = new Thickness(0, 0, 0, 0);
                var logo = VisualTreeHelperExtensions.GetDescendantsOfType <Canvas>(RootHub).FirstOrDefault(elem => elem.Name == "Logo");
                if (logo != null)
                {
                    (logo.RenderTransform as TranslateTransform).X = 0;
                }
            }
#elif WINDOWS_UWP
            LastReadSection.Width = Math.Min(LastReadSection.ActualHeight * 0.75, Math.Max(pageRoot.ActualWidth - 60, 0));

            if (appView.Orientation == ApplicationViewOrientation.Landscape)
            {
                LastReadSection.Margin = new Thickness(0, -52, 0, 0);
                var logo = VisualTreeHelperExtensions.GetDescendantsOfType <Canvas>(RootHub).FirstOrDefault(elem => elem.Name == "Logo");
                if (logo != null)
                {
                    (logo.RenderTransform as TranslateTransform).X = LastReadSection.ActualWidth;
                }

                SwitchGridViewOrientation(FavoriteSection.GetFirstDescendantOfType <GridView>(), Orientation.Horizontal);
                SwitchGridViewOrientation(RecentReadingSection.GetFirstDescendantOfType <GridView>(), Orientation.Horizontal);
                SwitchGridViewOrientation(RecommandSection.GetFirstDescendantOfType <GridView>(), Orientation.Horizontal, 6);

                Grid.SetRow(ToolBar, 0);
                ToolBar.HorizontalAlignment = HorizontalAlignment.Right;
                ToolBar.Background          = (SolidColorBrush)App.Current.Resources["TransparentBrush"];

                // Move the tool bar since the close/minumize button is dismissed
                var titleBar = CoreApplication.GetCurrentView().TitleBar;

                if (!titleBar.IsVisible || UIViewSettings.GetForCurrentView().UserInteractionMode == UserInteractionMode.Touch)
                {
                    ToolBar.Margin = new Thickness(0, -5, 0, 0);
                }
                else
                {
                    ToolBar.Margin = new Thickness(0, -5, titleBar.SystemOverlayRightInset, 0);
                }
                Window.Current.SetTitleBar(TooBarBackground);
            }
            else
            {
                LastReadSection.Margin = new Thickness(0, 0, 0, 0);
                var logo = VisualTreeHelperExtensions.GetDescendantsOfType <Canvas>(RootHub).FirstOrDefault(elem => elem.Name == "Logo");
                if (logo != null)
                {
                    (logo.RenderTransform as TranslateTransform).X = 0;
                }
                SwitchGridViewOrientation(FavoriteSection.GetFirstDescendantOfType <GridView>(), Orientation.Vertical);
                SwitchGridViewOrientation(RecentReadingSection.GetFirstDescendantOfType <GridView>(), Orientation.Vertical);
                SwitchGridViewOrientation(RecommandSection.GetFirstDescendantOfType <GridView>(), Orientation.Vertical, 6);

                Window.Current.SetTitleBar(null);
                Grid.SetRow(ToolBar, 2);
                ToolBar.Background          = (SolidColorBrush)App.Current.Resources["AppAccentBrush"];
                ToolBar.Padding             = new Thickness(0);
                ToolBar.Margin              = new Thickness(0);
                ToolBar.HorizontalAlignment = HorizontalAlignment.Stretch;
            }
#elif WINDOWS_APP
            if (appView.Orientation == ApplicationViewOrientation.Landscape)
            {
                LastReadSection.Margin = new Thickness(0, -79, 0, 0);
                LastReadSection.Width  = (this.ActualHeight - 80) * 0.6;
                LogoImage.Margin       = new Thickness(this.ActualHeight * 0.6 + 40, 0, 0, 0);
                LogoShiftingFactor     = 1.0;
                LastReadSection.Width  = 600;
            }
            else
            {
                LastReadSection.Margin = new Thickness(0, 0, 0, 0);
                LastReadSection.Width  = (this.ActualHeight - 80) * 0.6;
                LogoImage.Margin       = new Thickness(20, 0, 0, 0);
                LogoShiftingFactor     = 0.1;
            }
#endif
        }