L
L
LiptonOlolo2018-07-26 03:26:09
WPF
LiptonOlolo, 2018-07-26 03:26:09

Why does ListView's SelectedItem fire only once, while SelectedIndex always fires?

view:

<ListView ItemsSource="{Binding Items}" 
      SelectedItem="{Binding SelectedItem}"
      SelectedIndex="{Binding SelectedIndex}"/>

viewmodel:
public MyTestModel SelectedItem
{
  get => selected;
  set
  {
    selected = value;
    Debug.WriteLine("SelectedItem");
    RaisePropertyChanged();
  }
}

public int SelectedIndex
{
  get => index;
  set
  {
    index = value;
    Debug.WriteLine("SelectedIndex");
    RaisePropertyChanged();
  }
}

A couple of times click on the el-there in the list and in the output we will see:

SelectedItem
SelectedIndex
SelectedIndex
SelectedIndex

What's wrong with him?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Роман, 2018-07-27
@WNeZRoS

А что у вас в Items?
Я такое поведение видел только когда в Items одинаковые элементы (ReferenceEquals(a, b) == true)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question