gpt4 book ai didi

c# - OnPropertyChanged 上的 "Property Get method was not found"错误

转载 作者:行者123 更新时间:2023-11-30 21:49:09 32 4
gpt4 key购买 nike

我得到了错误

Additional information: Property Get method was not found when invoking OnPropertyChanged.

我的想法是我有一个 ListView有多个项目可供选择和SelectionMode="Multiple" .每次在 ListView 中单击一个项目我想将它添加到 ObservableCollection<Inspection> .

目前我是这样做的:

Xaml:

<ListView x:Name="Reports"
Margin="0,5,0,0"
RelativePanel.Below="ListViewHeader"
SelectionMode="Multiple"
ItemsSource="{Binding inspectionCatalogSingleton.Inspections}"
SelectedItem="{Binding SelectedInspections, Mode=TwoWay}">
</ListView>

View 模型:

public ReportViewModel()
{
_selectedInspections = new ObservableCollection<Inspection>();
}

private ObservableCollection<Inspection> _selectedInspections;
public Inspection SelectedInspections
{
set
{
_selectedInspections.Add(value);
OnPropertyChanged();
}
}

/*....*/

public event PropertyChangedEventHandler PropertyChanged;

[NotifyPropertyChangedInvocator]
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}

我在属性的 set 部分设置了一个断点,它进入正常但是当我单击继续时错误在这一行上升:

PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));

我在这里做错了什么?

最佳答案

由于 OnPropertyChanged 将指示 wpf 更新所有引用的绑定(bind),因此它需要一种获取属性值的方法。

您的 Property SelectedInspections 缺少 Getter。这就是您收到此异常/错误消息的原因。

关于c# - OnPropertyChanged 上的 "Property Get method was not found"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37179023/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com