public static Layout CreateToolbarPlacementChanger(Xamarin.Forms.Page page)
        {
            var enumType = typeof(ToolbarPlacement);

            return(CreateChanger(enumType, Enum.GetName(enumType, page.On <Windows>().GetToolbarPlacement()), picker =>
            {
                page.On <Windows>().SetToolbarPlacement((ToolbarPlacement)Enum.Parse(enumType, picker.Items[picker.SelectedIndex]));
            }, "Select Toolbar Placement"));
        }
Beispiel #2
0
        private void SetSafeInset(object sender, EventArgs e)
        {
            Xamarin.Forms.Page page = sender as Xamarin.Forms.Page;
            SafeInsets = page.On <Xamarin.Forms.PlatformConfiguration.iOS>().SafeAreaInsets();

            if (Device.RuntimePlatform == Device.iOS)
            {
                try
                {
                    // modifica il padding se è un iPhone X
                    if (SafeInsets.Top > 0)
                    {
                        Thickness headerPadding = (OnPlatform <Thickness>)Application.Current.Resources["HeaderPadding"];
                        headerPadding.Top = SafeInsets.Top;
                        Application.Current.Resources["HeaderPadding"] = headerPadding;

                        Thickness footerPadding = (OnPlatform <Thickness>)Application.Current.Resources["FooterPadding"];
                        footerPadding.Bottom = SafeInsets.Bottom;
                        Application.Current.Resources["FooterPadding"] = footerPadding;
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                }
            }

            Application.Current.Resources["SafeInsets"] = SafeInsets;

            page.Appearing -= SetSafeInset; //unsubscribe from event
        }
Beispiel #3
0
        public static void InitSafeAreaInsets(this Page page)
        {
            var safeInsets = page.On <iOS>().SafeAreaInsets();

            safeInsets.Top    = 0;
            safeInsets.Bottom = safeInsets.Bottom * -1;

            Application.Current.Resources["SafeAreaInsets"] = safeInsets;
        }
 private void AdjustInsets(Xamarin.Forms.Page page)
 {
     if (!(Device.RuntimePlatform == "Android"))
     {
         Thickness padding = page.On <iOS>().SafeAreaInsets();
         if (DeviceDisplay.MainDisplayInfo.Orientation == DisplayOrientation.Landscape)
         {
             page.Padding = default(Thickness);
         }
         else
         {
             padding.Top    = 30.0;
             padding.Bottom = 0.0;
             page.Padding   = padding;
         }
         if (_forceUseSafeInsets)
         {
             page.Padding = page.On <iOS>().SafeAreaInsets();
         }
     }
 }
Beispiel #5
0
 public static Thickness GetSafeAreaPaddingiOSX(Xamarin.Forms.Page page)
 {
     if (CommonMethod.CheckIsIphoneX())
     {
         var safeInsets  = page.On <Xamarin.Forms.PlatformConfiguration.iOS>().SafeAreaInsets();
         var orientation = DeviceDisplay.MainDisplayInfo.Orientation;
         if (orientation == DisplayOrientation.Portrait)
         {
             safeInsets.Right = 30;
             safeInsets.Left  = 30;
         }
         else if (orientation == DisplayOrientation.Landscape)
         {
             safeInsets.Right = 30;
             safeInsets.Left  = 30;
         }
         return(safeInsets);
     }
     else
     {
         return(0);
     }
 }
Beispiel #6
0
        /// <summary>
        /// Resolves a View and its related ViewModel
        /// </summary>
        /// <param name="viewModelType">The ViewModel type</param>
        /// <param name="vm">The output ViewModel instance</param>
        /// <returns>The ViewModel instance</returns>
        public Xamarin.Forms.Page Resolve(Type viewModelType, out IViewModel viewModel)
        {
            var vm = _resolver.Resolve(viewModelType) as ViewModel;

            Xamarin.Forms.Application.Current.On <iOS>().SetPanGestureRecognizerShouldRecognizeSimultaneously(true);

            Xamarin.Forms.Page view = null;
            ViewMapAttribute   map  = _mappings[viewModelType];

            if (vm == null || map == null)
            {
                throw new InvalidOperationException("View Model not mapped!");
            }

            Xamarin.Forms.Page pageView = _resolver.Resolve(map.View) as Xamarin.Forms.Page;

            if (pageView == null)
            {
                string message = string.Format("Page not mapped! View Model: {0}", viewModelType);
                throw new InvalidOperationException(message);
            }

            if (map.MenuViewModel == null)
            {
                view = pageView;
                view.On <iOS>().SetUseSafeArea(true);
            }
            else
            {
                IViewModel         menuViewModel = null;
                Xamarin.Forms.Page menuView      = Resolve(map.MenuViewModel, out menuViewModel);

                if (menuView != null)
                {
                    pageView.BindingContext = vm;
                    pageView.Parent         = null;
                    menuView.Parent         = null;

                    if (string.IsNullOrWhiteSpace(menuView.Title))
                    {
                        menuView.Title = menuView.GetType().Name;
                    }

                    if (string.IsNullOrWhiteSpace(pageView.Title))
                    {
                        pageView.Title = pageView.GetType().Name;
                    }

                    view = new MasterDetailPage
                    {
                        Master = menuView,
                        Detail = pageView
                    };

                    pageView.On <iOS>().SetUseSafeArea(true);
                }
            }

            view.Title          = vm.Title;
            view.BindingContext = vm;

            if (map.HideNavigation)
            {
                Xamarin.Forms.NavigationPage.SetHasNavigationBar(view, false);
            }

            viewModel = vm;

            return(view);
        }