Attached Behavior to execute command for ListViewItem

后端 未结 1 981
逝去的感伤
逝去的感伤 2021-02-06 05:51

I am trying to use an attached behavior to execute a command in my ViewModel when the user Double Clicks on the list item.

I have reviewed a number of articles on the su

相关标签:
1条回答
  • 2021-02-06 06:04

    The problem is that the DataContext for the Binding is the string. Since there is no Foo property of the string class, you are getting an error. This doesn't happen in the other cases because they inherit their DataContext from the parent (this doesn't happen for automatically generated containers for data items - their DataContext is the data item).

    If you change your binding to use the parent ListView's DataContext, it should work fine:

    Value="{Binding DataContext.Foo, RelativeSource={RelativeSource AncestorType={x:Type ListView}}}"
    
    0 讨论(0)
提交回复
热议问题