开发者

WPF TreeViewItem dyanmic context menu

I'm having some trouble with a databound TreeView in WPF, basically I want a context menu to开发者_运维问答 be databound to an IEnumerable property on my TreeViewItem ViewModel, this is what I'm trying to do in the of each TreeViewItem:

<Setter Property="ContextMenu">
<Setter.Value>
    <ContextMenu ItemsSource="{Binding ContextMenu}" />
</Setter.Value>

but it gives me an exception when loading the xaml saying it can't set ContextMenu on System.Object or something along those lines.

Can anyone shed some light on this?

Thanks


declare it as resource in your style and then assign it to Value as StaticResource

<Style>
  <Style.Resources>
    <ContextMenu x:Key="contextmenustyle" ItemsSource="{Binding ContextMenu}" />
  </Style.Resources>
  <Setter Property="ContextMenu" Value="{StaticResource contextmenustyle}">
</Style>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜