简体   繁体   English

使用Prism框架隐藏Xamarin.Forms中的选项卡

[英]Hiding a tab in Xamarin.Forms using Prism framework

I am working on a Xamarin Forms project that uses an MVVM pattern and Prism. 我正在开发一个使用MVVM模式和Prism的Xamarin Forms项目。

My issue is, I need to be able to hide a tab on a tab page based off of a bool. 我的问题是,我需要能够根据bool隐藏标签页上的标签。 There is a bindable property in the XAML called "IsVisible", which I assumed would hide the tab from the user, but instead the tab still shows but displays a blank page when selected. 在XAML中有一个名为“IsVisible”的可绑定属性,我假设该属性会隐藏用户的选项卡,但选项卡仍会显示,但在选中时会显示空白页面。

Currently my XAML looks like this 目前我的XAML看起来像这样

<?xml version="1.0" encoding="utf-8"?>
<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
        xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
        xmlns:prism="clr-namespace:Prism.Mvvm;assembly=Prism.Forms"
        xmlns:local="clr-namespace:com.XXXXXXX"
        prism:ViewModelLocator.AutowireViewModel="True"

        BackgroundColor="White"
        x:Class="com.XXXXXXXXXX.EditChargePage"
        Title="{Binding Title}">

<local:EditChargeDetailsPage Title="Details" />
<local:EditChargeTrackingPage Title="Tracking" IsVisible="{Binding TabContext.HasTracking}" IsEnabled="{Binding TabContext.HasTracking}"/>
<local:EditChargeNotesPage Title="Notes" />


</TabbedPage>

Originally to solve the problem I just used "IsVisible", when that didn't work as expected I added "IsEnabled" which didn't seem to do anything. 最初是为了解决我刚刚使用“IsVisible”的问题,当它没有按预期工作时,我添加了“IsEnabled”,似乎没有做任何事情。

Is there a way to hide the Tab from the UI using a boolean value in Xamarin (or Prism for Xamarin) without breaking MVVM? 有没有办法在不破坏MVVM的情况下使用Xamarin(或Prism for Xamarin)中的布尔值从UI中隐藏Tab?

You might want to check out the Prism Samples . 您可能想查看Prism Samples The TabbedNavigation sample demonstrates how to initialize your tabbed children with INavigatingAware or the IEventAggregator , as well as dynamically adding the tabs at run time. TabbedNavigation示例演示了如何使用INavigatingAwareIEventAggregator初始化选项卡式子IEventAggregator ,以及在运行时动态添加选项卡。 If you need even finer control, such as a value in a ViewModel of one of your Child Pages that determines whether some other page should be shown, then you could use this to publish an event with the IEventAggregator and subscribe to that event in your TabbedPage to handle adding or removing the page. 如果您需要更精细的控制,例如您的某个子页面的ViewModel中的值,以确定是否应显示其他页面,那么您可以使用它来使用IEventAggregator发布事件并在TabbedPage中订阅该事件处理添加或删除页面。

Unfortunately IsVisible and IsEnabled do not actually work within a TabbedPage the way you were hoping. 不幸的是, IsVisibleIsEnabled实际上并不像你希望的那样在TabbedPage中工作。 So the only way you can accomplish this is to actually manipulate the Children of the TabbedPage directly pushing or popping them from the collection. 因此,实现此目的的唯一方法是实际操作TabbedPage的Children,直接从集合中推送或弹出它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Xamarin.Forms中使用Prism在页面之间导航? - How to navigate between pages using Prism in Xamarin.Forms? 如何使用Prism / DryIoC在Xamarin.Forms中解决IValueConverter中的依赖关系 - How to resolve a dependency in IValueConverter in Xamarin.Forms using Prism/DryIoC 在Xamarin.Forms中,无法与Prism合作 - INavigation not working with Prism in Xamarin.Forms Xamarin.Prism无法自动连线的棱镜 - Prism for Xamarin.Forms unable to AutoWire Xamarin.Forms Prism中特定于平台的代码 - Platform specific code in Xamarin.Forms Prism 如何使用“ Xamarin.Forms”中的“ Prism.Forms”绑定视图和查看存在于不同dll中的模型? - How to bind views and view models that exist in different dlls using “Prism.Forms” in “Xamarin.Forms”? Xamarin.Forms中的实体框架7 - Entity Framework 7 in Xamarin.Forms Xamarin形式:Prism框架FileNotFoundException-Prism.Forms - Xamarin forms : Prism framework FileNotFoundException - Prism.Forms SyncFusion SfRichTextEditor 不会在 Android 上使用 Prism、Xamarin.Forms 返回编辑过的文本 - SyncFusion SfRichTextEditor doesn't return edited text using Prism, Xamarin.Forms on Android Xamarin.Forms Prism-使用导航服务从一个详细信息页面导航到另一个 - Xamarin.Forms Prism - Using navigation service to navigate from one detail page to another
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM