TreeViewItem.Expanded

前端 未结 2 1987
清歌不尽
清歌不尽 2021-01-14 23:36

Im using the latest version of mvvm light toolkit, however i\'m not clear how I can use EventToCommand for the event TreeViewItem.Expanded.

THis dosent work... what

2条回答
  •  长情又很酷
    2021-01-15 00:15

    The event to command behavior is implemented as an attached property, which must be attached to a FrameworkElement. Your sample has the Triggers attached property attached to the TreeView which doesn't have an Expanded or Collapsed event. You attempted to use "TreeViewItem.Expanded" as the event name, but it doesn't work that way.

    If you were creating your TreeViewItems statically in XAML, or manually in code-behind, you could attach to each TreeViewItem. Unfortunately, I'm not aware of any way to attach to the TreeViewItem from the HierarchicalDataTemplate. You can bind to the TemplatedParent RelativeSource, but you can't attach to it. Your only solution is to iterate through the TreeViewItems in code-behind, and manually handle the events, but even then you'd have to do so using the VisualTreeHelper only after the TreeView control has been data bound and rendered, which is a huge hack.

提交回复
热议问题