gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 16:40:51 25 4
gpt4 key购买 nike

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

最佳答案

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

please check the solution here

作为回顾:
在 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());
}
}
}
}

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

在启动时调用它

在 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 共享页面或项目调用它
/* arabic */
DependencyService.Get<IPathManager>().SetLayoutRTL();

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

English - hamburger menu icon on the LEFT.
ARABIC - hamburger menu icon on the RIGHT.

不要忘记设置语言更改的流向
if(lang==3)
{//arabic
this.FlowDirection = FlowDirection.RightToLeft;
this.Master.FlowDirection= FlowDirection.RightToLeft;
this.Detail.FlowDirection= FlowDirection.RightToLeft;

}

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

干杯,
拉比

关于xamarin.forms - Xamarin.Forms v3 中的 MasterDetail + 从右到左,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50392534/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com