在我们的应用程序中,有一个主 - 详细信息容器作为主视图容器。我们希望将选项卡页面作为主 - 详细信息容器的详细信息页面,以便用户能够通过菜单和选项卡栏执行导航。 Exrin有没有办法实现这个目标? 据我们所知,支持master-detail页面和tabbed页面。如何将这些页面组合在一起?
答案 0 :(得分:0)
你需要有Exrin 2.0.2及更高版本才能工作。
首先,您需要稍微更新包含MasterDetailPage的Container。接口定义略有改变。
public class MainContainer : ViewContainer, IMasterDetailContainer
{
private MasterDetailPage page;
public MainContainer(TabbedViewContainer mainStack, MenuStack menuStack)
: base(Containers.Main.ToString())
{
page = new MasterDetailPage();
var mdp = new MasterDetailProxy(page);
NativeView = mdp.View;
Proxy = mdp;
DetailStack = mainStack;
MasterStack = menuStack;
RegionMapping.Add(Regions.Menu, ContainerType.Master);
RegionMapping.Add(Regions.Main, ContainerType.Detail);
}
private IHolder _detailStack;
public IHolder DetailStack { get { return _detailStack; } set { _detailStack = value; if (_detailStack is ITabbedContainer container) ((ViewContainer)container).ParentContainer = this; } }
private IHolder _masterStack;
public IHolder MasterStack { get { return _masterStack; } set { _masterStack = value; if (_masterStack is ITabbedContainer container) ((ViewContainer)container).ParentContainer = this; } }
public IMasterDetailProxy Proxy { get; set; }
public bool IsPresented
{
get
{
return page.IsPresented;
}
set
{
page.IsPresented = value;
}
}
public void SetStack(ContainerType type, object newPage)
{
switch (type)
{
case ContainerType.Detail:
page.Detail = newPage as Page;
break;
case ContainerType.Master:
page.Master = newPage as Page;
break;
}
}
}
其次,请注意,不是在构造函数中使用Stack,而是通过TabbedViewContainer,并根据需要进行分配。您的TabbedViewContainer可能看起来像这样。
public class TabbedViewContainer : Exrin.Framework.ViewContainer, ITabbedContainer
{
public TabbedViewContainer(MainStack mainStack, SecondStack secondStack)
: base(Containers.Tabbed.ToString(), null)
{
Children = new List<IStack>() { mainStack, secondStack };
var tabbedPage = new Xamarin.Forms.TabbedPage();
var tabbed = new TabbedProxy(tabbedPage);
NativeView = tabbed.View;
foreach (var child in Children)
{
tabbed.Children.Add(child.Proxy.NativeView);
}
}
public IList<IStack> Children { get; set; }
}