Xamarin.Forms v3中的MasterDetail +从右到左 [英] MasterDetail + Right-to-Left in Xamarin.Forms v3

查看:113
本文介绍了Xamarin.Forms v3中的MasterDetail +从右到左的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是从右到左的新表格功能,除了MasterDetail汉堡菜单图标以外,其他所有功能都很好.它停留在左侧,我需要将其移至右侧,因为本地化已更改.有什么想法或有人可以帮助我使用自定义渲染器吗?

I'm using new forms feature Right-to-Left, it works well except MasterDetail hamburger menu icon. It stays on the left side and I need to move it to right whem localization is changed. Any ideas or could somebody help me with custom renderer?

推荐答案

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

well not impossible but some dirty coding is needed:

请在此处检查解决方案

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

as recap: To force the layout RTL and LTR on IOS:

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());
        }
    }
 }
} 

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

ps: please change "yourproject" to your project name...

要在启动时调用

在AppDelegate.cs中

in 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));

要从PCL共享页面或项目中调用

TO call this from the PCL shared pages or project

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

/* English */
DependencyService.Get<IPathManager>().SetLayoutLTR();

别忘了设置语言更改的流向

Don't forget to set the flow direction on language change

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

                } 

希望这会有所帮助!所有这些汉堡图标!

hope this helps! all this for that hamburger icon !!!

干杯, 拉比

这篇关于Xamarin.Forms v3中的MasterDetail +从右到左的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆