BindingExpression path error: property not found on 'object'

后端 未结 2 1934
我在风中等你
我在风中等你 2020-12-31 17:39

I\'ve been searching for hours on this error that appears in the output window. I\'m pretty new to bindings in WPF, so I\'m sure there\'s something I\'m missing.

Ful

相关标签:
2条回答
  • 2020-12-31 18:11

    seems like you're binding your listviews itemssource to an object, not an array. is everything working visually? or do you see nothing?

    EDIT: what happens if you write instead of:

    <c:MyData x:Key="myDataSource"/>
    

    this:

    <x:Array x:Key="myDataSource" Type="{x:Type c:MyData}">
      <c:MyData />      
    </x:Array>
    

    or any likewise collection definition

    0 讨论(0)
  • 2020-12-31 18:27

    You don't want to set the DataContext on the UserControl. Instead, you want to set it in the scope of the UserControl.

    Usually you do this in the constructor of the UserControl. I usually add a line like this:

    this.RootElement.DataContext = myData;
    

    Where RootElement is the first sub-element (the Content) of your UserControl (usually a panel like Grid or StackPanel).

    In your case it would be:

    this.lsvwOutput.DataContext = FindResource("myDataSource");

    And makes sure that it's after the InitializeComponent() call.

    It's just a question of scoping. You set the datacontext on the root panel of the usercontrol. This is a really non-obvious part of WPF.

    UPDATE: As Markus points out below, in the case of a listview, you want to set an array of data, not just a data point. Take that into consideration when setting the DataContext in your constructor.

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