我在iOS和android的Xamarin表单上使用MasterDetailPage for app.
但是MasterDetailPage菜单中的宽度太大,我想对其进行调整.
如何在Android和iOS上为MasterDetailPage设置自定义宽度?
我的MasterDetailPage初始化代码:
MyChatsMasterVIEw _myChatsMasterVIEw; MyChatsVIEw _myChatsVIEw; public MyChatsMasterDetailVIEw(MyChatsMasterVIEw myChatsMasterVIEw, MyChatsVIEw myChatsVIEw) { NavigationPage.SetHasNavigationbar(this, false); InitializeComponent(); this.MasterBehavior = MasterBehavior.Popover; _myChatsMasterVIEw = myChatsMasterVIEw; _myChatsVIEw = myChatsVIEw; Master = _myChatsMasterVIEw; Detail = _myChatsVIEw; _myChatsMasterVIEw.SetDetailVIEw(this); }
解决方法:
我通过从Xamarin.Forms源复制渲染器解决了该问题.
基本上,我需要一个宽度为400 dp的母版,以便在其中正确显示日历.
这是我所做的:
共享图书馆
我创建了一个从MasterDetail页面派生的SplitVIEwPage:
<?xml version="1.0" enCoding="utf-8" ?><MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="CompApp.VIEws.SplitVIEwPage"> <MasterDetailPage.Master> <ContentPage title=" "/> </MasterDetailPage.Master> <MasterDetailPage.Detail> <ContentPage title=" "/> </MasterDetailPage.Detail></MasterDetailPage>
安卓系统
由于主宽度是内部类’MasterDetailContainer’中的常量,因此我从基类复制了代码(请参见here)
更改为名为“ DroIDMasterDetailContainer.cs”的新类,同时将类的可见性从内部更改为公共.
我对代码进行了两项更改:
>我将const int DefaultMasterSize = 320更改为const int DefaultMasterSize = 400
>我将_childVIEw.ClearValue(Platform.rendererProperty)行注释掉; (第116行,由于无法访问Platform.rendererProperty,因此位于voID disposeChildRenderers()中)
下一步是将MasterDetailRenderer的代码(请参见here)复制到新类(在我的情况下为’SplitVIEwPageRenderer.cs’)
using System;using System.ComponentModel;using System.linq;using System.Threading.Tasks;using AndroID.App;using AndroID.Content;using AndroID.OS;using AndroID.Support.V4.Widget;using AndroID.VIEws;using MyApp.DroID.Renderer;using Xamarin.Forms;using Xamarin.Forms.Platform.AndroID;using Xamarin.Forms.Platform.AndroID.AppCompat;using Acolor = AndroID.Graphics.Drawables.colorDrawable;using AVIEw = AndroID.VIEws.VIEw;[assembly: ExportRenderer(typeof(SplitVIEwPage), typeof(SplitVIEwPageRenderer))]namespace MyApp.DroID.Renderer{public class SplitVIEwPageRenderer : DrawerLayout, IVisualElementRenderer, DrawerLayout.IDrawerListener{ public SplitVIEwPageRenderer(Context context) : base(context) { } //from AndroID source code const uint DefaultScrimcolor = 0x99000000; int _currentLockMode = -1; DroIDMasterDetailContainer _detailLayout; bool _isPresentingFromCore; DroIDMasterDetailContainer _masterLayout; MasterDetailPage _page; bool _presented; [Obsolete("This constructor is obsolete as of version 2.5. Please use MasterDetailRenderer(Context) instead.")] public SplitVIEwPageRenderer() : base(Forms.Context) { } IMasterDetailPageController MasterDetailPageController => _page as IMasterDetailPageController; public bool Presented { get { return _presented; } set { if (value == _presented) return; UpdateSplitVIEwLayout(); _presented = value; if (_page.MasterBehavior == MasterBehavior.Default && MasterDetailPageController.ShouldShowSplitMode) return; if (_presented) OpenDrawer(_masterLayout); else CloseDrawer(_masterLayout); } } IPageController MasterPageController => _page.Master as IPageController; IPageController DetailPageController => _page.Detail as IPageController; IPageController PageController => Element as IPageController; public voID OnDrawerClosed(AVIEw drawerVIEw) { } public voID OnDrawerOpened(AVIEw drawerVIEw) { } public voID OnDrawerSlIDe(AVIEw drawerVIEw, float slIDeOffset) { } public voID OnDrawerStateChanged(int newState) { _presented = IsDrawerVisible(_masterLayout); UpdateIsPresented(); } public VisualElement Element { get { return _page; } } public event EventHandler<VisualElementChangedEventArgs> ElementChanged; event EventHandler<PropertyChangedEventArgs> ElementPropertyChanged; event EventHandler<PropertyChangedEventArgs> IVisualElementRenderer.ElementPropertyChanged { add { ElementPropertyChanged += value; } remove { ElementPropertyChanged -= value; } } public SizeRequest GetDesiredSize(int wIDthConstraint, int heightConstraint) { Measure(wIDthConstraint, heightConstraint); return new SizeRequest(new Size(MeasureDWIDth, MeasuredHeight)); } public voID SetElement(VisualElement element) { MasterDetailPage oldElement = _page; _page = element as MasterDetailPage; _detailLayout = new DroIDMasterDetailContainer(_page, false, Context) { LayoutParameters = new LayoutParams(VIEwGroup.LayoutParams.WrapContent, VIEwGroup.LayoutParams.WrapContent) }; _masterLayout = new DroIDMasterDetailContainer(_page, true, Context) { LayoutParameters = new LayoutParams(VIEwGroup.LayoutParams.WrapContent, VIEwGroup.LayoutParams.WrapContent) { Gravity = (int)GravityFlags.Start } }; AddVIEw(_detailLayout); AddVIEw(_masterLayout); var activity = Context as Activity; activity.Actionbar.SetdisplayShowHomeEnabled(true); activity.Actionbar.SetHomebuttonEnabled(true); UpdateBackgroundcolor(_page); UpdateBackgroundImage(_page); OnElementChanged(oldElement, element); if (oldElement != null) ((IMasterDetailPageController)oldElement).Backbuttonpressed -= OnBackbuttonpressed; if (_page != null) MasterDetailPageController.Backbuttonpressed += OnBackbuttonpressed; if (Tracker == null) Tracker = new VisualElementTracker(this); _page.PropertyChanged += HandlePropertyChanged; _page.Appearing += MasterDetailPageAppearing; _page.disappearing += MasterDetailPagedisappearing; UpdateMaster(); UpdateDetail(); Device.Info.PropertyChanged += DeviceInfoPropertyChanged; SetGestureState(); Presented = _page.IsPresented; AddDrawerListener(this); //if (element != null) // element.SendVIEwInitialized(this); if (element != null && !string.IsNullOrEmpty(element.automationID)) ContentDescription = element.automationID; } public VisualElementTracker Tracker { get; private set; } public voID UpdateLayout() { if (Tracker != null) Tracker.UpdateLayout(); } public VIEwGroup VIEwGroup => this; AVIEw IVisualElementRenderer.VIEw => this; protected overrIDe voID dispose(bool disposing) { if (disposing) { if (Tracker != null) { Tracker.dispose(); Tracker = null; } if (_detailLayout != null) { _detailLayout.dispose(); _detailLayout = null; } if (_masterLayout != null) { _masterLayout.dispose(); _masterLayout = null; } Device.Info.PropertyChanged -= DeviceInfoPropertyChanged; if (_page != null) { MasterDetailPageController.Backbuttonpressed -= OnBackbuttonpressed; _page.PropertyChanged -= HandlePropertyChanged; _page.Appearing -= MasterDetailPageAppearing; _page.disappearing -= MasterDetailPagedisappearing; //_page.ClearValue(Platform.rendererProperty); _page = null; } } base.dispose(disposing); } protected overrIDe voID OnAttachedToWindow() { base.OnAttachedToWindow(); PageController.SendAppearing(); } protected overrIDe voID OnDetachedFromWindow() { base.OnDetachedFromWindow(); PageController.Senddisappearing(); } protected virtual voID OnElementChanged(VisualElement oldElement, VisualElement newElement) { EventHandler<VisualElementChangedEventArgs> changed = ElementChanged; if (changed != null) changed(this, new VisualElementChangedEventArgs(oldElement, newElement)); } protected overrIDe voID OnLayout(bool changed, int l, int t, int r, int b) { base.OnLayout(changed, l, t, r, b); //Hack to make the split layout handle touches the full wIDth if (MasterDetailPageController.ShouldShowSplitMode && _masterLayout != null) _masterLayout.Right = r; } async voID DeviceInfoPropertyChanged(object sender, PropertyChangedEventArgs e) { if (e.Propertyname == "CurrentOrIEntation") { if (!MasterDetailPageController.ShouldShowSplitMode && Presented) { MasterDetailPageController.CanChangeIsPresented = true; //Hack : when the orIEntation changes and we try to close the Master on AndroID //sometimes AndroID picks the wIDth of the screen prevIoUs to the rotation //this leaves a little of the master visible, the Hack is to delay for 50ms closing the drawer await Task.Delay(50); CloseDrawer(_masterLayout); } UpdateSplitVIEwLayout(); } } voID HandleMasterPropertyChanged(object sender, PropertyChangedEventArgs e) { //if (e.Propertyname == Page.TitleProperty.Propertyname || e.Propertyname == Page.IconProperty.Propertyname) //((Platform)_page.Platform).UpdateMasterDetailToggle(true); } voID HandlePropertyChanged(object sender, PropertyChangedEventArgs e) { ElementPropertyChanged?.Invoke(this, e); if (e.Propertyname == "Master") UpdateMaster(); else if (e.Propertyname == "Detail") { UpdateDetail(); //((Platform)_page.Platform).UpdateActionbar(); } else if (e.Propertyname == MasterDetailPage.IsPresentedProperty.Propertyname) { _isPresentingFromCore = true; Presented = _page.IsPresented; _isPresentingFromCore = false; } else if (e.Propertyname == "IsGestureEnabled") SetGestureState(); else if (e.Propertyname == Page.BackgroundImageProperty.Propertyname) UpdateBackgroundImage(_page); if (e.Propertyname == VisualElement.BackgroundcolorProperty.Propertyname) UpdateBackgroundcolor(_page); } voID MasterDetailPageAppearing(object sender, EventArgs e) { MasterPageController?.SendAppearing(); DetailPageController?.SendAppearing(); } voID MasterDetailPagedisappearing(object sender, EventArgs e) { MasterPageController?.Senddisappearing(); DetailPageController?.Senddisappearing(); } voID OnBackbuttonpressed(object sender, BackbuttonpressedEventArgs backbuttonpressedEventArgs) { if (IsDrawerOpen((int)GravityFlags.Start)) { if (_currentLockMode != LockModeLockedOpen) { CloseDrawer((int)GravityFlags.Start); backbuttonpressedEventArgs.Handled = true; } } } voID SetGestureState() { SetDrawerLockMode(_page.IsGestureEnabled ? LockModeUnlocked : LockModeLockedClosed); } voID IVisualElementRenderer.SetLabelFor(int? ID) { } voID SetLockMode(int lockMode) { if (_currentLockMode != lockMode) { SetDrawerLockMode(lockMode); _currentLockMode = lockMode; } } voID UpdateBackgroundcolor(Page vIEw) { if (vIEw.Backgroundcolor != color.Default) SetBackgroundcolor(vIEw.Backgroundcolor.ToAndroID()); } voID UpdateBackgroundImage(Page vIEw) { if (!string.IsNullOrEmpty(vIEw.BackgroundImage)) this.SetBackground(Context.GetDrawable(vIEw.BackgroundImage)); } voID UpdateDetail() { Context.HIDeKeyboard(this); _detailLayout.ChildVIEw = _page.Detail; } voID UpdateIsPresented() { if (_isPresentingFromCore) return; if (Presented != _page.IsPresented) ((IElementController)_page).SetValueFromrenderer(MasterDetailPage.IsPresentedProperty, Presented); } voID UpdateMaster() { if (_masterLayout != null && _masterLayout.ChildVIEw != null) _masterLayout.ChildVIEw.PropertyChanged -= HandleMasterPropertyChanged; _masterLayout.ChildVIEw = _page.Master; if (_page.Master != null) _page.Master.PropertyChanged += HandleMasterPropertyChanged; } voID UpdateSplitVIEwLayout() { if (Device.Idiom == TargetIdiom.tablet) { bool isShowingSplit = MasterDetailPageController.ShouldShowSplitMode || (MasterDetailPageController.ShouldShowSplitMode && _page.MasterBehavior != MasterBehavior.Default && _page.IsPresented); SetLockMode(isShowingSplit ? LockModeLockedOpen : LockModeUnlocked); unchecked { SetScrimcolor(isShowingSplit ? color.transparent.ToAndroID() : (int)DefaultScrimcolor); } //((Platform)_page.Platform).UpdateMasterDetailToggle(); } }}}
请注意,我们使用的是之前创建的’DroIDMasterDetailContainer’,而不是对变量_masterLayout和_detailLayout使用内部类’MasterDetailContainer’.
的iOS
基本上是相同的故事:使用MasterDetailRenderer代码(请参见here),创建您自己的类,粘贴代码和一些改编,稍后我们将:
using CompApp.Customs;using MyApp.iOS.Renderer;using System;using System.Collections.Generic;using System.Text;using Xamarin.Forms;using Xamarin.Forms.Platform.iOS;using System.ComponentModel;using CoreGraphics;using MyApp.VIEws;using UIKit;using Xamarin.Forms.Internals;using System.Reflection;[assembly: ExportRenderer(typeof(SplitVIEwPage), typeof(SplitVIEwPageRenderer))]namespace MyApp.iOS.Renderer{public class SplitVIEwPageRenderer : UISplitVIEwController, IVisualElementRenderer, IEffectControlProvIDer{ UIVIEwController _detailController; bool _disposed; EventTracker _events; InnerDelegate _innerDelegate; public static nfloat MasterWIDth = 400; EventedVIEwController _masterController; SplitVIEwPage _masterDetailPage; bool _masterVisible; VisualElementTracker _tracker; Page PageController => Element as Page; Element ElementController => Element as Element; protected SplitVIEwPage MasterDetailPage => _masterDetailPage ?? (_masterDetailPage = (SplitVIEwPage)Element); public VisualElement Element { get; private set; } public event EventHandler<VisualElementChangedEventArgs> ElementChanged; UIbarbuttonItem Presentbutton { get { return _innerDelegate == null ? null : _innerDelegate.Presentbutton; } } public UIVIEw NativeVIEw { get { return VIEw; } } protected virtual voID OnElementChanged(VisualElementChangedEventArgs e) { if (e.oldElement != null) e.oldElement.PropertyChanged -= HandlePropertyChanged; if (e.NewElement != null) { e.NewElement.PropertyChanged += HandlePropertyChanged; } if (UIDevice.CurrentDevice.OrIEntation == UIDeviceOrIEntation.Landscapeleft || UIDevice.CurrentDevice.OrIEntation == UIDeviceOrIEntation.LandscapeRight) { PreferreddisplayMode = UISplitVIEwControllerdisplayMode.AllVisible; } else if (UIDevice.CurrentDevice.OrIEntation == UIDeviceOrIEntation.Portrait || UIDevice.CurrentDevice.OrIEntation == UIDeviceOrIEntation.PortraitUpsIDeDown) { PreferreddisplayMode = UISplitVIEwControllerdisplayMode.PrimaryOverlay; } MasterWIDth = 400; MasterDetailPage.Master.WIDthRequest = 400; MasterDetailPage.UpdateMasterBehavior(); var changed = ElementChanged; if (changed != null) changed(this, e); UpdateControllers(); } public SizeRequest GetDesiredSize(double wIDthConstraint, double heightConstraint) { return NativeVIEw.GetSizeRequest(wIDthConstraint, heightConstraint); } public voID SetElement(VisualElement element) { var oldElement = Element; Element = element; VIEwControllers = new[] { _masterController = new EventedVIEwController(), _detailController = new ChildVIEwController() }; Delegate = _innerDelegate = new InnerDelegate(MasterDetailPage.MasterBehavior); Element.Backgroundcolor = color.transparent; UpdateControllers(); _masterController.WillAppear += MasterControllerWillAppear; _masterController.Willdisappear += MasterControllerWilldisappear; PresentsWithGesture = MasterDetailPage.IsGestureEnabled; OnElementChanged(new VisualElementChangedEventArgs(oldElement, element)); EffectUtilitIEs.RegisterEffectControlProvIDer(this, oldElement, element); if (element != null) { MethodInfo sendVIEwInitialized = typeof(Xamarin.Forms.Forms).getmethod("SendVIEwInitialized", BindingFlags.Static | BindingFlags.NonPublic); sendVIEwInitialized?.Invoke(element, new object[] { element, NativeVIEw }); } } public voID SetElementSize(Size size) { Element.Layout(new Rectangle(Element.X, Element.WIDth, size.WIDth, size.Height)); } public UIVIEwController VIEwController { get { return this; } } public overrIDe voID VIEwDIDAppear(bool animated) { PageController.SendAppearing(); base.VIEwDIDAppear(animated); ToggleMaster(); } public overrIDe voID VIEwDIDdisappear(bool animated) { base.VIEwDIDdisappear(animated); PageController?.Senddisappearing(); } public overrIDe voID VIEwDIDLayoutSubvIEws() { if (VIEw.SubvIEws.Length < 2) return; var frameBounds = VIEw.Bounds; var masterBounds = _masterController.VIEw.Frame; var detailsBounds = _detailController.VIEw.Frame; nfloat statusbarHeight = UIApplication.SharedApplication.StatusbarFrame.Height; masterBounds.WIDth = 400; MasterWIDth = (nfloat)Math.Max(MasterWIDth, masterBounds.WIDth); if (Xamarin.Forms.Device.Idiom == TargetIdiom.tablet) { bool interfaceInLandscape = UIApplication.SharedApplication.StatusbarOrIEntation == UIInterfaceOrIEntation.Landscapeleft || UIApplication.SharedApplication.StatusbarOrIEntation == UIInterfaceOrIEntation.LandscapeRight; if (UIDevice.CurrentDevice.OrIEntation == UIDeviceOrIEntation.Landscapeleft || UIDevice.CurrentDevice.OrIEntation == UIDeviceOrIEntation.LandscapeRight || interfaceInLandscape) { detailsBounds.X = 400; detailsBounds.WIDth = frameBounds.WIDth - 400; } else { detailsBounds.X = 0; detailsBounds.WIDth = frameBounds.WIDth; } _detailController.VIEw.Frame = detailsBounds; _masterController.VIEw.Frame = new CGRect(masterBounds.X, masterBounds.Y, masterBounds.WIDth, masterBounds.Height); if (!masterBounds.IsEmpty) { MasterDetailPage.MasterBounds = new Rectangle(masterBounds.X, masterBounds.Y, masterBounds.WIDth, masterBounds.Height); } if (!detailsBounds.IsEmpty) { MasterDetailPage.DetailBounds = new Rectangle(detailsBounds.X, detailsBounds.Y, detailsBounds.WIDth, detailsBounds.Height); } _masterController.VIEw.SetNeedsLayout(); _detailController.VIEw.SetNeedsLayout(); } else { if (!masterBounds.IsEmpty) { MasterDetailPage.MasterBounds = new Rectangle(MasterWIDth, 0, MasterWIDth, masterBounds.Height); } if (!detailsBounds.IsEmpty) { MasterDetailPage.DetailBounds = new Rectangle(0, 0, detailsBounds.WIDth, detailsBounds.Height); } } } public overrIDe voID VIEwDIDLoad() { base.VIEwDIDLoad(); UpdateBackground(); UpdateFlowDirection(); _tracker = new VisualElementTracker(this); _events = new EventTracker(this); _events.LoadEvents(NativeVIEw); } public overrIDe voID VIEwWilldisappear(bool animated) { if (_masterVisible) PerformbuttonSelector(); base.VIEwWilldisappear(animated); } public overrIDe voID VIEwWillLayoutSubvIEws() { base.VIEwWillLayoutSubvIEws(); _masterController.VIEw.Backgroundcolor = UIcolor.White; CGRect bounds = _masterController.VIEw.Bounds; CGRect frame = _masterController.VIEw.Frame; (this.VIEwController as UISplitVIEwController).MinimumPrimaryColumnWIDth = 400; (this.VIEwController as UISplitVIEwController).MaximumPrimaryColumnWIDth = 400; } public overrIDe voID WillRotate(UIInterfaceOrIEntation toInterfaceOrIEntation, double duration) { // On IOS8 the MasterVIEwController VIEwAppear/disappear weren't being called correctly after rotation // We Now close the Master by using the new SplitVIEw API, basicly we set it to hIDden and right back to the normal/automaticMode if (!MasterDetailPage.ShouldShowSplitMode && _masterVisible) { MasterDetailPage.CanChangeIsPresented = true; PreferreddisplayMode = UISplitVIEwControllerdisplayMode.PrimaryHIDden; PreferreddisplayMode = UISplitVIEwControllerdisplayMode.automatic; } var masterBounds = _masterController.VIEw.Frame; MessagingCenter.Send<IVisualElementRenderer>(this, "Xamarin.Updatetoolbarbuttons"); MasterDetailPage.UpdateMasterBehavior(); base.WillRotate(toInterfaceOrIEntation, duration); } public overrIDe voID DIDRotate(UIInterfaceOrIEntation fromInterfaceOrIEntation) { base.DIDRotate(fromInterfaceOrIEntation); var masterBounds = _masterController.VIEw.Frame; MasterWIDth = (nfloat)Math.Max(MasterWIDth, masterBounds.WIDth); if (!masterBounds.IsEmpty) { MasterDetailPage.MasterBounds = new Rectangle(MasterWIDth, 0, MasterWIDth, masterBounds.Height); } } public overrIDe UIVIEwController ChildVIEwControllerForStatusbarHIDden() { if (((MasterDetailPage)Element).Detail != null) return (UIVIEwController)Platform.GetRenderer(((MasterDetailPage)Element).Detail); else return base.ChildVIEwControllerForStatusbarHIDden(); } voID ClearControllers() { foreach (var controller in _masterController.ChildVIEwControllers) { controller.VIEw.RemoveFromSupervIEw(); controller.RemoveFromParentVIEwController(); } foreach (var controller in _detailController.ChildVIEwControllers) { controller.VIEw.RemoveFromSupervIEw(); controller.RemoveFromParentVIEwController(); } } voID HandleMasterPropertyChanged(object sender, PropertyChangedEventArgs e) { if (e.Propertyname == Page.IconProperty.Propertyname || e.Propertyname == Page.TitleProperty.Propertyname) MessagingCenter.Send<IVisualElementRenderer>(this, "Xamarin.Updatetoolbarbuttons"); } voID HandlePropertyChanged(object sender, PropertyChangedEventArgs e) { if (_tracker == null) return; if (e.Propertyname == "Master" || e.Propertyname == "Detail") UpdateControllers(); else if (e.Propertyname == Xamarin.Forms.MasterDetailPage.IsPresentedProperty.Propertyname) ToggleMaster(); else if (e.Propertyname == Xamarin.Forms.MasterDetailPage.IsGestureEnabledProperty.Propertyname) base.PresentsWithGesture = this.MasterDetailPage.IsGestureEnabled; else if (e.Propertyname == "FlowDirection") UpdateFlowDirection(); MessagingCenter.Send<IVisualElementRenderer>(this, "Xamarin.Updatetoolbarbuttons"); } voID MasterControllerWillAppear(object sender, EventArgs e) { _masterVisible = true; if (MasterDetailPage.CanChangeIsPresented) ElementController.SetValueFromrenderer(Xamarin.Forms.MasterDetailPage.IsPresentedProperty, true); } voID MasterControllerWilldisappear(object sender, EventArgs e) { _masterVisible = false; if (MasterDetailPage.CanChangeIsPresented) ElementController.SetValueFromrenderer(Xamarin.Forms.MasterDetailPage.IsPresentedProperty, false); } voID PerformbuttonSelector() { displayModebuttonItem.Target.PerformSelector(displayModebuttonItem.Action, displayModebuttonItem, 0); } voID ToggleMaster() { if (_masterVisible == MasterDetailPage.IsPresented || MasterDetailPage.ShouldShowSplitMode) return; PerformbuttonSelector(); } voID UpdateBackground() { if (!string.IsNullOrEmpty(((Page)Element).BackgroundImage)) VIEw.Backgroundcolor = UIcolor.FromPatternImage(UIImage.FromBundle(((Page)Element).BackgroundImage)); else if (Element.Backgroundcolor == color.Default) VIEw.Backgroundcolor = UIcolor.White; else VIEw.Backgroundcolor = Element.Backgroundcolor.ToUIcolor(); } voID UpdateControllers() { MasterDetailPage.Master.PropertyChanged -= HandleMasterPropertyChanged; if (Platform.GetRenderer(MasterDetailPage.Master) == null) Platform.SetRenderer(MasterDetailPage.Master, Platform.CreateRenderer(MasterDetailPage.Master)); if (Platform.GetRenderer(MasterDetailPage.Detail) == null) Platform.SetRenderer(MasterDetailPage.Detail, Platform.CreateRenderer(MasterDetailPage.Detail)); ClearControllers(); MasterDetailPage.Master.PropertyChanged += HandleMasterPropertyChanged; var master = Platform.GetRenderer(MasterDetailPage.Master).VIEwController; var detail = Platform.GetRenderer(MasterDetailPage.Detail).VIEwController; _masterController.VIEw.AddSubvIEw(master.VIEw); _masterController.AddChildVIEwController(master); _detailController.VIEw.AddSubvIEw(detail.VIEw); _detailController.AddChildVIEwController(detail); } voID UpdateFlowDirection() { bool ios9orLater = UIDevice.CurrentDevice.CheckSystemVersion(9, 0); if (NativeVIEw == null || VIEw == null || !ios9orLater) return; VIEw.SemanticContentAttribute = UISemanticContentAttribute.ForceleftToRight; } class InnerDelegate : UISplitVIEwControllerDelegate { Readonly MasterBehavior _masterPresentedDefaultState; public InnerDelegate(MasterBehavior masterPresentedDefaultState) { _masterPresentedDefaultState = masterPresentedDefaultState; } public UIbarbuttonItem Presentbutton { get; set; } public overrIDe bool ShouldHIDeVIEwController(UISplitVIEwController svc, UIVIEwController vIEwController, UIInterfaceOrIEntation inorIEntation) { bool willHIDeVIEwController; switch (_masterPresentedDefaultState) { case MasterBehavior.Split: willHIDeVIEwController = false; break; case MasterBehavior.Popover: willHIDeVIEwController = true; break; case MasterBehavior.SplitOnPortrait: willHIDeVIEwController = !(inorIEntation == UIInterfaceOrIEntation.Portrait || inorIEntation == UIInterfaceOrIEntation.PortraitUpsIDeDown); break; default: willHIDeVIEwController = inorIEntation == UIInterfaceOrIEntation.Portrait || inorIEntation == UIInterfaceOrIEntation.PortraitUpsIDeDown; break; } return willHIDeVIEwController; } public overrIDe voID WillHIDeVIEwController(UISplitVIEwController svc, UIVIEwController aVIEwController, UIbarbuttonItem barbuttonItem, UIPopoverController pc) { Presentbutton = barbuttonItem; } } voID IEffectControlProvIDer.RegisterEffect(Effect effect) { VisualElementRenderer<VisualElement>.RegisterEffect(effect, VIEw); } protected overrIDe voID dispose(bool disposing) { if (_disposed) { return; } _disposed = true; if (disposing) { if (Element != null) { PageController.Senddisappearing(); Element.PropertyChanged -= HandlePropertyChanged; if (MasterDetailPage?.Master != null) { MasterDetailPage.Master.PropertyChanged -= HandleMasterPropertyChanged; } Element = null; } if (_tracker != null) { _tracker.dispose(); _tracker = null; } if (_events != null) { _events.dispose(); _events = null; } if (_masterController != null) { _masterController.WillAppear -= MasterControllerWillAppear; _masterController.Willdisappear -= MasterControllerWilldisappear; } ClearControllers(); } base.dispose(disposing); }}internal class ChildVIEwController : UIVIEwController{ public overrIDe voID VIEwDIDLayoutSubvIEws() { foreach (var vc in ChildVIEwControllers) { CGRect rect = VIEw.Bounds; vc.VIEw.Frame = rect; } }}internal class EventedVIEwController : ChildVIEwController{ public overrIDe voID VIEwWillAppear(bool animated) { base.VIEwWillAppear(animated); var eh = WillAppear; if (eh != null) eh(this, EventArgs.Empty); } public overrIDe voID VIEwWilldisappear(bool animated) { base.VIEwWilldisappear(animated); var eh = Willdisappear; if (eh != null) eh(this, EventArgs.Empty); } public overrIDe voID VIEwDIDLayoutSubvIEws() { CGRect rect = VIEw.Bounds; VIEw.Bounds = rect; foreach (var vc in ChildVIEwControllers) { rect = vc.VIEw.Frame; vc.VIEw.Frame = rect; rect = vc.VIEw.Bounds; vc.VIEw.Bounds = rect; } } public event EventHandler WillAppear; public event EventHandler Willdisappear;}}
我仅使用tabletMasterDetailRenderer,因为我使用MasterDetailVIEw为平板电脑设备创建了一个特定的视图,该设备在主机内部包含一个日历视图,并在详细信息视图中显示所选条目的详细信息.
如果您需要用于手机,则也可以使用PhoneMasterDetailRenderer进行相同的更改.
总结以上是内存溢出为你收集整理的CodeGo.net>如何在Xamarin形式设置MasterDetailPage的宽度全部内容,希望文章能够帮你解决CodeGo.net>如何在Xamarin形式设置MasterDetailPage的宽度所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)