WPF ListBox not updating with the ItemsSource

后端 未结 3 1845
花落未央
花落未央 2020-12-20 14:42

I have what I believe should be simple two-way databinding in WPF setup, but the listbox (target) is not updating as the collection changes.

I\'m setting this ItemsS

相关标签:
3条回答
  • 2020-12-20 15:10

    i got stuck for more than hour and then simple logic solved this problem just set itemsource to clear list and then set source u need again

    lstVariable_Selected.ItemsSource = new List<Object>();
    lstVariable_Selected.ItemsSource = m_VariableList;
    
    0 讨论(0)
  • 2020-12-20 15:25

    The problem is not in the XAML that you have provided. I used the same XAML successfully in a test application; however, I was able to replicate the issue you are experiencing by re-instantiating the m_VariableList variable.

    When the m_VariableList is given a new instance, or pointed to a new object, it is not reflected in the ListBox because the control has its own reference to the data. This may not be the cause of your problem, but I'd recommend looking over your code-behind to ensure that the variable is not getting re-instantiated.

    0 讨论(0)
  • 2020-12-20 15:27

    Is your m_VariableList implementing INotifyCollectionChanged? If it's not an ObservableCollection, then changes to it's contents will not automatically be reflected in the UI.

    0 讨论(0)
提交回复
热议问题