Prism共享视图模型

时间:2017-11-21 22:13:20

标签: c# xamarin xamarin.forms prism

  • 平台:Xamarin表格
  • 棱镜版本:6.3.0
  • Xamarin版本(如适用):2.3.4

你好,我正在使用棱镜。我有一个Tabbedpage如何为所有女儿的观点共享一个视图模型?

我的xaml:

<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:views="clr-namespace:MySednaApp.Views;assembly=MySednaApp"
          xmlns:view="clr-namespace:MySednaApp.View;assembly=MySednaApp"
          prism:ViewModelLocator.AutowireViewModel="True"
          x:Class="MySednaApp.Views.PubblicaArticoliTabbedPage"
          Title="{view:Translate PubblicaArticoli}" 
  <TabbedPage.ToolbarItems 
      <ToolbarItem x:Name="Delete2" Icon="ico_delete.png" Text="Elimina"    Command="{Binding delete}"    
          <ToolbarItem.Order 
              <OnPlatform x:TypeArguments="ToolbarItemOrder" 
                  <On Platform="iOS" Primary</On 
                  <On Platform="Android" Secondary</On 
              </OnPlatform 
          </ToolbarItem.Order 
      </ToolbarItem 
      <ToolbarItem x:Name="Save" Icon="ico_save.png"  Command="{Binding save}"  Order="Primary" Priority="0" / 
  </TabbedPage.ToolbarItems 
  <views:PubblicaArticoliDettaglioPage x:Name="pubblicaArticoliDettaglioPage"/ 
  <views:PubblicaArticoliGaugePage  x:Name="pubblicaArticoliGaugePage"/ 
  <views:PubblicaArticoliFotoPage  x:Name="pubblicaArticoliFotoPage"/ 
</TabbedPage 

2 个答案:

答案 0 :(得分:1)

简单,只需将每个选项卡的BindingContext设置为代码隐藏中的TabbedPage的BindingContext。

答案 1 :(得分:0)

您必须在XAML页面中添加这些属性才能绑定viewmodel

xmlns:mvvm="clr-namespace:Prism.Mvvm;assembly=Prism.Forms"
mvvm:ViewModelLocator.AutowireViewModel="True"