ContentView中ContentView的参考元素

时间:2019-06-25 01:33:49

标签: xaml data-binding xamarin.forms

在我的ContentView(name = CvProduct)内,我有一个ListView(nam = LvProducts)和每个单元格中的几个控件,它们的特定命令可在页面的(name = Products)视图模型(name = ProductsViewModel)中访问。 我无法使绑定生效。

t = new Thread(this, name);

总是返回此错误:

  

Message =“位置xyz找不到<ContentPage x:Name="Products"> <ContentPage.Resources> <ResourceDictionary> <DataTemplate x:Key="ContentTemplate"> <views:CvProduct/> </DataTemplate> </ResourceDictionary> </ContentPage.Resources> </ContentPage> <ContentView x:Name="CvProduct"> <xForms:SfListView x:Name="LvProducts"> <xForms:SfListView.ItemTemplate> <DataTemplate> <forms:SvgCachedImage.GestureRecognizers> <TapGestureRecognizer Command="{Binding BindingContext.ConsultElement, Source={x:Reference Name=LvProducts}}" CommandParameter="{Binding .}"> </forms:SvgCachedImage.GestureRecognizers> </DataTemplate> </xForms:SfListView.ItemTemplate> </xForms:SfListView> </ContentView> 引用的对象”

1 个答案:

答案 0 :(得分:0)

在名为MyCommand的页面的绑定上下文中引用命令myPage

Command="{Binding Source={x:Reference Name=myPage}, 
                  Path=BindingContext.MyCommand}" 

在包含ListView的名为MyCommand的布局的绑定上下文中引用命令myLayout

Command="{Binding Source={x:Reference Name=myLayout}, 
                  Path=BindingContext.MyCommand}"