Forum Xamarin.Forms
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

MasterDetailPage icon right and drawer open from right to left

Hi
How MasterDetailPage icon align to right?
and how drawer open from right to left?
Please give us code if you did it. Thank you

Best Answer

  • mammadkomamammadkoma Member ✭✭
    edited June 2018 Accepted Answer

    Yes I did it

    manifest :

    <application android:label="Sanaap" android:icon="@mipmap/launcher_foreground" android:theme="@style/MainTheme" android:supportsRtl="true">

    MainView.xaml

    <MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms"
                 xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                 x:Class="Sanaap.App.Views.MenuView" 
                 FlowDirection="RightToLeft"
                 Title="Main">
    

Answers

  • 15mgm1515mgm15 USMember ✭✭✭✭
  • mammadkomamammadkoma Member ✭✭
    edited June 2018

    Thank you 15mgm15
    this sample creates MyMasterDetailPageRenderer in android project :
    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.Gravity = (int)GravityFlags.Right;
                _masterLayout.LayoutParameters = lp;
            }
        }
    

    and use it in xamarin forms app.xaml :
    public App()
    {
    InitializeComponent();

                var mdp = new MasterDetailPage
                {
                    Master = new ContentPage
                    {
                        BackgroundColor = Color.Lime,
                        Title = "Master",
                        Content = new Label
                        {
                            Text = "MasterPage",
                            HorizontalTextAlignment = TextAlignment.Center,
                            VerticalTextAlignment = TextAlignment.Center,
                        },
                    },
                    Detail = new ContentPage
                    {
                        BackgroundColor = Color.Gray,
                        Title = "DetailPage",
                        Content = new Label
                        {
                            Text = "DetailPage",
                            HorizontalTextAlignment = TextAlignment.Center,
                            VerticalTextAlignment = TextAlignment.Center,
                        },
                    },
                };
    
                MainPage = mdp;
            }
    

    and only where is the icon on action bar?
    how can I add the icon and align it to the right?

  • mammadkomamammadkoma Member ✭✭

    we must drag and drop and there is no icon on action bar

  • _Jai_Jai USMember ✭✭

    @mammadkoma I hope you have solved this problem if not then check that you have assign page to the detail page in masterpagexaml.cs

  • mammadkomamammadkoma Member ✭✭
    edited June 2018

    xamarin forms is realy restricted and weak in UI.

  • mammadkomamammadkoma Member ✭✭
    edited June 2018 Accepted Answer

    Yes I did it

    manifest :

    <application android:label="Sanaap" android:icon="@mipmap/launcher_foreground" android:theme="@style/MainTheme" android:supportsRtl="true">

    MainView.xaml

    <MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms"
                 xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                 x:Class="Sanaap.App.Views.MenuView" 
                 FlowDirection="RightToLeft"
                 Title="Main">
    
  • mammadkomamammadkoma Member ✭✭
    edited June 2018

    But this forum has vary errors to post text

  • @mammadkoma
    What About is Icon, it's dont move between right to left

  • minakhminakh Member ✭✭

    @MohanadAbusbib
    You should create a NavigationPageRenderer class in android and set toolbar layoutdirection to RTL

  • stXamDevstXamDev Member ✭✭✭

    Anyone figure this out on iOS

Sign In or Register to comment.