【问题标题】:Changing BindingContext in listView template does not point to Viewmodel在 listView 模板中更改 BindingContext 不指向 Viewmodel
【发布时间】:2021-09-05 12:46:50
【问题描述】:

通过添加更改 listView 中按钮的 BindingContext 时

      BindingContext="{Binding Source={x:Reference parentContePage}}"
      Command="{Binding ViewPdf}"    

由于某种原因,应用程序试图在视图类中查找方法,而我在输出控制台中遇到错误

[0:] Binding: 'ViewPdf' property not found on 'WinterEventMobileForm.UI.Pages.ReservationView'

parentContePage 元素

<views:MvxContentPage xmlns="http://xamarin.com/schemas/2014/forms"
                      x:Name="parentContePage"
                xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                x:TypeArguments="viewModels:ReservationViewModel"
                xmlns:views="clr-namespace:MvvmCross.Forms.Views;assembly=MvvmCross.Forms"
                xmlns:viewModels="clr-namespace:WinterEventMobileForm.Core.ViewModels;assembly=WinterEventMobileForm.Core" 
                xmlns:navigationdrawer="clr-namespace:Syncfusion.SfNavigationDrawer.XForms;assembly=Syncfusion.SfNavigationDrawer.XForms" 
                xmlns:buttons="clr-namespace:Syncfusion.XForms.Buttons;assembly=Syncfusion.Buttons.XForms" 
                xmlns:view="clr-namespace:WinterEventMobileForm.UI.Pages"
                xmlns:ListView="clr-namespace:Syncfusion.ListView.XForms;assembly=Syncfusion.SfListView.XForms" 
                xmlns:core="clr-namespace:Syncfusion.XForms.Core;assembly=Syncfusion.Core.XForms"
                x:Class="WinterEventMobileForm.UI.Pages.ReservationView" 
                xmlns:controls="clr-namespace:WinterEventMobileForm.UI.Controls" xmlns:border="clr-namespace:Syncfusion.XForms.Border;assembly=Syncfusion.Core.XForms"
                      Title="test"
                NavigationPage.HasNavigationBar="False"
                        xmlns:mvx="clr-namespace:MvvmCross.Forms.Bindings;assembly=MvvmCross.Forms"
                >

为什么 x:Reference 返回 View 而不是 ViewModel?

【问题讨论】:

    标签: xamarin.forms mvvmcross


    【解决方案1】:

    通过修改命令解决的问题:

    Command="{Binding ViewModel.ViewPdf}"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-12-25
      • 2019-09-24
      • 1970-01-01
      • 2023-04-03
      • 1970-01-01
      • 2013-07-31
      • 2020-06-29
      相关资源
      最近更新 更多