首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >来自ContentView在ContentView中的引用元素

来自ContentView在ContentView中的引用元素
EN

Stack Overflow用户
提问于 2019-06-25 01:33:49
回答 1查看 649关注 0票数 0

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

代码语言:javascript
复制
<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>

它总是返回此错误:

Message =“LvProducts无法找到LvProducts引用的对象”

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-06-25 08:42:53

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

代码语言:javascript
复制
Command="{Binding Source={x:Reference Name=myPage}, 
                  Path=BindingContext.MyCommand}" 

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

代码语言:javascript
复制
Command="{Binding Source={x:Reference Name=myLayout}, 
                  Path=BindingContext.MyCommand}" 
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56745720

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档