ListBoxItem produces “System.Windows.Data Error: 4” binding error

前端 未结 3 1058
粉色の甜心
粉色の甜心 2020-12-14 01:14

I have created the fallowing ListBox:



        
3条回答
  •  渐次进展
    2020-12-14 01:41

    The answer over here resolved this issue for me:

    ListBox with Grid as ItemsPanelTemplate produces weird binding errors

    Defining a top-level style (in my App.xaml) targeting the problem type "fixed" the issue for me. Here's a style that should work for you:

    
    

    In my case, I was creating some TreeViewItems and then binding my TreeView to the created items. The binding error was occurring because the TreeViewItem's binding was being resolved before they were being added to the TreeView. The correct solution was to not create a TreeViewItem, but instead create a class that contained the data I needed (Header and Items). Just relaying my situation in case there are parallels with your own.

提交回复
热议问题