2016-05-12 109 views
2

錯誤我得到的錯誤「屬性GET方法未找到」上OnPropertyChanged

其他信息:房產獲取調用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> 

視圖模型:

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)); 
} 

我在的設定部分設置斷點財產,它進入罰款但是當我點擊繼續錯誤在這條線上升:

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

我在這裏做錯了什麼?

+3

我可能會誤解,但您在SelectedInspections屬性中缺少一個吸氣劑。 – Xeun

+0

我會盡力實現這一點。問題是,雖然我的私人財產是一個可觀察的收集,公衆的是一種類型的檢驗。 – Evilunclebill

+0

@Xeun解決了錯誤!謝謝! 介意將其設置爲答案,以便我可以接受? – Evilunclebill

回答

2

由於OnPropertyChanged將指示wpf更新所有引用的綁定,因此它需要一種方法來獲取該屬性的值。

您的屬性SelectedInspections上缺少一個Getter。 這就是爲什麼你收到這個異常/錯誤消息。