【发布时间】:2020-04-26 23:05:13
【问题描述】:
现在我开始使用 Prism Framework for xamarine,但在实现跨视图连接时遇到了一点问题。
我有这个文件夹“Views”,在里面我有另一个名为 PartialViews 的文件夹。现在在 PartialViews 中,我有一个名为“Header.xaml”的 contentPage。 现在我想将此文件附加到位于 Views 文件夹中的 Index.xaml 视图。我还想将“Header.xaml”附加到其他视图,例如我想将它附加到“Orders.xaml”视图。
我的 Header.xaml 文件如下:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:prism="http://prismlibrary.com"
xmlns:local="clr-namespace:PROJECTX.Views"
prism:ViewModelLocator.AutowireViewModel="True"
x:Class="PROJECTX.Views.Header">
<StackLayout>
<Label Text="Trying partial views" />
</StackLayout>
</ContentPage>
而我的 Index.xaml 如下:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:combobox="clr-namespace:Syncfusion.XForms.ComboBox;assembly=Syncfusion.SfComboBox.XForms"
xmlns:ListCollection="clr-namespace:System.Collections.Generic;assembly=mscorlib"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:prism="http://prismlibrary.com"
xmlns:local="clr-namespace:PROJECTX.Views"
prism:ViewModelLocator.AutowireViewModel="True"
x:Class="PROJECTX.Views.Index"
x:Name="selfi">
<ScrollView>
<local:Header mvvm:ViewModelLocator.AutowirePartialView="{x:Reference selfi}" />
<combobox:SfComboBox x:Name="comboBox">
<combobox:SfComboBox.ComboBoxSource>
<ListCollection:List x:TypeArguments="x:String">
<x:String>Rendit sipas: Me te kerkuara</x:String>
<x:String>Rendit sipas: Te fundit</x:String>
<x:String>Rendit sipas: Alfabetit</x:String>
</ListCollection:List>
</combobox:SfComboBox.ComboBoxSource>
</combobox:SfComboBox>
</ScrollView>
</ContentPage>
我还在我的 App.xaml.cs 上使用这样的视图模型注册了 PartialViews 文件夹的路由:
protected override void RegisterTypes(IContainerRegistry containerRegistry)
{
containerRegistry.RegisterForNavigation<NavigationPage>();
containerRegistry.RegisterForNavigation<MainPage, MainPageViewModel>();
containerRegistry.RegisterForNavigation<Index, IndexViewModel>();
//containerRegistry.RegisterForNavigation<Header, HeaderViewModel>();
ViewModelLocationProvider.Register<Header, HeaderViewModel>();
}
现在我遇到了一些错误......
1. The property 'Content' is set more than once.
2. The attachable property 'AutowirePartialView' was not found in type 'ViewModelLocator'.
3. Property 'Content' does not support values of type 'Header'.
现在我知道这可能是一个菜鸟问题,但我似乎无法让它处理这个部分视图的事情。 我对 xamarin 中部分视图的理解是否正确?我应该从视图中调用部分视图..正确吗?
任何帮助我都会非常感激。
【问题讨论】:
标签: c# xaml xamarin xamarin.forms prism