在Xamarin android中从右向左滑动抽屉

少年击剑更吹箫,剑气箫心一例消。这篇文章主要讲述在Xamarin android中从右向左滑动抽屉相关的知识,希望能为你提供帮助。

我有问题从右到左为xamarin android打开滑动抽屉。但是下面用于显示滑动的代码
抽屉从左到右。如果MasterDetailPage的任何属性从右向左打开,请与我分享您的观点。这里滑动抽屉从左到右打开,但我想从右到左打开Xamarin Android任何关于此的想法。请分享你的想法。我们还使用MenuRootPage在Sliding Drawer中添加项目:
Code for items view:

< ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" > < ContentPage.Content> < StackLayoutBackgroundColor="{StaticResource ToolbarStatusBackgroundColor}"Orientation="Vertical" Spacing="20"> < StackLayout> < StackLayout.GestureRecognizers> < TapGestureRecognizer Command="{mm:Command SliderClose}" /> < /StackLayout.GestureRecognizers> < Image Source="menu.png" HorizontalOptions="Start" Margin="10,40,0,0" /> < /StackLayout> < BoxView HorizontalOptions="EndAndExpand"HeightRequest="1" WidthRequest="1000" Color="{StaticResource SeparatorColor}"/> < Label Text="My account" Style="{StaticResource ToolbarStatusDescriptionLabel}" Margin="10"> < Label.GestureRecognizers> < TapGestureRecognizer Command="{mm:Command SliderClose}" /> < /Label.GestureRecognizers> < /Label> < BoxView HorizontalOptions="EndAndExpand"HeightRequest="1" WidthRequest="1000" Color="{StaticResource SeparatorColor}"/> < Label Text="Settings" Style="{StaticResource ToolbarStatusDescriptionLabel}" Margin="10"> < Label.GestureRecognizers> < TapGestureRecognizer Command="{mm:Command SliderClose}" /> < /Label.GestureRecognizers> < /Label> < BoxView HorizontalOptions="EndAndExpand"HeightRequest="1" WidthRequest="1000" Color="{StaticResource SeparatorColor}"/> < Label Text="Logout" Style="{StaticResource ToolbarStatusDescriptionLabel}" HorizontalTextAlignment="Center"VerticalOptions="EndAndExpand" Margin="10"> < Label.GestureRecognizers> < TapGestureRecognizerCommand="{mm:Command Logout}" /> < /Label.GestureRecognizers> < /Label> < /StackLayout> < /ContentPage.Content> < /ContentPage> In MenuRootPage .xaml file we are declare master page only UI section In MenuRootPage .cs file: here we are inherit MasterDetailPage propertiesUsing code: Root page in MenuRootPage .xaml file: < MasterDetailPagexmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="Ansible.Vektor.App.Shared.Views.MenuRootPage" > < /MasterDetailPage> Root MenuRootPage .cs file: public partial class MenuRootPage : MasterDetailPage { public MenuRootPage () { InitializeComponent(); MasterBehavior = MasterBehavior.Popover; } }App.xaml.cs:var menuPage = new MenuPages() { BindingContext = MenuPagesViewModel }; NavigationPage = new NavigationPage(new MainView() { BindingContext = MainViewModel }); MenuRootPage = new MenuRootPage(); MenuRootPage.Master = menuPage; MenuRootPage.Detail = NavigationPage; MenuIsGestureEnabled = false; MainPage = MenuRootPage; Here Sliding Drawer open from left to right but i want to open from right to left for Xamarin Android Any idea regarding this. please share your idea's.

答案【在Xamarin android中从右向左滑动抽屉】在Android中为主细节页面进行自定义渲染。
public class MyMasterDetailPageRenderer : MasterDetailPageRenderer { protected override void OnElementChanged(VisualElement oldElement, VisualElement newElement) { base.OnElementChanged(oldElement, newElement); var fieldInfo = GetType().BaseType.GetField("_masterLayout", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic); var _masterLayout = (ViewGroup)fieldInfo.GetValue(this); var lp = new DrawerLayout.LayoutParams(_masterLayout.LayoutParameters); lp.Width = 300; lp.Gravity = (int)GravityFlags.Right; _masterLayout.LayoutParameters = lp; } }


    推荐阅读