Xamarin.Forms v3 中的 MasterDetail + 从右到左

Mil*_*lec 5 master-detail right-to-left xamarin.forms

我正在使用从右到左的新表单功能,除了 MasterDetail 汉堡菜单图标外,它运行良好。它保持在左侧,我需要将它移到右侧,因为本地化发生了变化。任何想法或有人可以帮助我自定义渲染器?

Rab*_*arb 4

也不是不可能,但需要一些肮脏的编码:

请在此处检查解决方案

回顾一下:在 IOS 上强制布局 RTL 和 LTR:

1-创建此类/服务

using System;
using System.IO;
using Xamarin.Forms;
using yourproject.iOS;
using yourproject.database;
using ObjCRuntime;
using System.Runtime.InteropServices;
using UIKit;
using System.Diagnostics;

[assembly: Dependency(typeof(PathManager_IOS))]
namespace yourproject.iOS
{
 public class PathManager_IOS : IPathManager
 {
[DllImport(ObjCRuntime.Constants.ObjectiveCLibrary, EntryPoint = "objc_msgSend")]
internal extern static IntPtr IntPtr_objc_msgSend(IntPtr receiver, IntPtr selector, UISemanticContentAttribute arg1);

    public PathManager_IOS()
    {

    }
   public void SetLayoutRTL()
    {
        try
        {
            Selector selector = new Selector("setSemanticContentAttribute:");
            IntPtr_objc_msgSend(UIView.Appearance.Handle, selector.Handle, UISemanticContentAttribute.ForceRightToLeft);
        }
        catch (Exception s)
        {
            Debug.WriteLine("failed to set layout...."+s.Message.ToString());
        }
    }
    public void SetLayoutLTR()
    {
        try
        {
            Selector selector = new Selector("setSemanticContentAttribute:");
            IntPtr_objc_msgSend(UIView.Appearance.Handle, selector.Handle, UISemanticContentAttribute.ForceLeftToRight);
        }
        catch (Exception s)
        {
            Debug.WriteLine("failed to set layout...." + s.Message.ToString());
        }
    }
 }
} 
Run Code Online (Sandbox Code Playgroud)

ps:请将“yourproject”更改为您的项目名称...

在启动时调用此方法

在 AppDelegate.cs 中

   PathManager_IOS pathManager = new PathManager_IOS();
   if (lang == 3)
    {
      pathManager.SetLayoutRTL();/* RTL */

    }
    if (lang == 1||lang == 2)
    {
       pathManager.SetLayoutLTR();/*   LTR   */
    }
    LoadApplication(new App(m, lang));
Run Code Online (Sandbox Code Playgroud)

从 PCL 共享页面或项目调用它

/* arabic */
DependencyService.Get<IPathManager>().SetLayoutRTL();

/* English */
DependencyService.Get<IPathManager>().SetLayoutLTR();
Run Code Online (Sandbox Code Playgroud)

英语 - 左侧的汉堡菜单图标。 阿拉伯语 - 右侧的汉堡菜单图标。

不要忘记设置语言更改时的流向

if(lang==3)
                {//arabic 
                    this.FlowDirection = FlowDirection.RightToLeft;
                    this.Master.FlowDirection= FlowDirection.RightToLeft;
                    this.Detail.FlowDirection= FlowDirection.RightToLeft;

                } 
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助!这一切都是为了那个汉堡图标!!!

干杯,拉比