【问题标题】:Xamarin Form ListView SelectedItem MVVM Binding Error XFC0009Xamarin 表单 ListView SelectedItem MVVM 绑定错误 XFC0009
【发布时间】:2021-11-08 10:51:18
【问题描述】:

我正在尝试使用 MVVM Archtecture 将 ListView 的 SelectedItem 绑定到 ViewModel Proper,但它提供了

错误 XFC0009 找不到“ItemSelected”的属性、BindableProperty 或事件,或者值和属性之间的类型不匹配。

E:\Xamarin\CoffeeAppListView\CoffeeAppListView\CoffeeAppListView\Views\CoffeeEquipmentPage.xaml(第 23 行)

代码sn-ps是

XML:

<ListView CachingStrategy="RecycleElement"
              BackgroundColor="Transparent"
              ItemsSource="{Binding CoffeeGroups}"
              IsGroupingEnabled="True"
              GroupDisplayBinding="{Binding Key}"
              HasUnevenRows="true"
              SeparatorVisibility="Default"
              IsPullToRefreshEnabled="True"
              IsRefreshing="{Binding IsBusy,Mode=OneWay}"
              RefreshCommand="{Binding RefreshCommand}"
              RefreshControlColor="DarkBlue"
              ItemSelected="{Binding SelectedCoffee, Mode=TwoWay}">

视图模型:

public Coffee SelectedCoffee
{
    get => selectedCoffee;
    set
    {
        if(value!=null)
        {
            Application.Current.MainPage.DisplayAlert("Selected", value.Name, "OK");
            previouslySeelcted = value;
            value = null;
        }
        selectedCoffee = value;
        OnPropertyChanged();
    }
}

【问题讨论】:

  • 您能分享您的整个 Xaml 页面吗?这可能是 te BindingContext 的问题

标签: c# xamarin.forms xamarin.android


【解决方案1】:

ItemSelected 是一个事件

SelectedItem 是可绑定属性

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-11-05
    • 2018-01-03
    • 2018-08-14
    • 1970-01-01
    • 2016-10-10
    • 2018-07-07
    • 1970-01-01
    相关资源
    最近更新 更多