Good afternoon, there is a collection which is filled from the MySQL base:
while (contains_result.Read()) { ItemsForContains.Add( new Contains() { CId = contains_result["id"].ToString(), ProfId = contains_result["profId"].ToString() }); } Class with properties:
public class Contains : INotifyPropertyChanged { private string _cid; private string _groupid; public string CId { get { return _cid; } set { if (_cid != value) { _cid = value; RaisePropertyChanged(); } } } public string GroupId { get { return _groupid; } set { if (_groupid != value) { _groupid = value; RaisePropertyChanged(); } } } protected void RaisePropertyChanged([CallerMemberName] string propertyName = null) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); public event PropertyChangedEventHandler PropertyChanged; } The whole thing is tied to a ListView (ItemsSource). I'm trying to do something when I clicked on one of the lines of the ListView for example, I gave out a MessageBox with the data of exactly the line to which I clicked. I do it like this: Binding to the SelectedItem in the ListView:
SelectedItem="{Binding SelectedItemsContains}" SelectedItemsContains:
private Contains _SelectedItemsContains; public Contains SelectedItemsContains { get { return _SelectedItemsContains; } set { _SelectedItemsContains = value; RaisePropertyChanged(); } } protected void RaisePropertyChanged([CallerMemberName] string propertyName = null) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); public event PropertyChangedEventHandler PropertyChanged; Well, the event itself on click:
private void editProf_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { MessageBox.Show(SelectedItemsContains.CId); } Displays "Object reference does not indicate an object instance." And if I add the line SelectedItemsContains = new Contains () to the editProf_MouseLeftButtonUp method; the error disappears, but displays just an empty MessageBox