After two days of googling and searching I give it up. Seems to me it is becoming big challenge :)
So I want to set two different context menus based on xml element name.
Lets say for group Add group and for document Add document
Prefering to do it in xaml without behind code.
One context menu should be when group element is right clicked other one when document element is clicked.
I have fairly simple xml structure:
="1.0"="utf-8"
<docspacket>
<packet>
<group>
<name>Home group</name>
<group>
<name>Other group</name>
<document>
<name>doc1</name>
</document>
<document>
<name>doc2</name>
</document>
</group>
<document>
<name>doc1</name>
</document>
<document>
<name>doc2</name>
</document>
</group>
</packet>
</docspacket>
So my treeView have HierachicalDataView:
<Grid.Resources>
<HierarchicalDataTemplate x:Key="Group" ItemsSource="{Binding XPath=./*[name]}">
<TextBlock Text="{Binding XPath=name}" />
</HierarchicalDataTemplate>
<XmlDataProvider x:Key="XmlNodeList" XPath="/docspacket/packet/*" Source="C:\Users\home\Documents\Visual Studio 2010\Projects\SimpleXMLparser\SimpleXMLparser\bin\Debug\XMLFile2.xml"/>
</Grid.Resources>
And treeView control:
<TreeView ItemTemplate="{StaticResource Group}" ItemsSource="{Binding Source={StaticResource XmlNodeList}}" Height="229" HorizontalAlignment="Left" Margin="254,41,0,0" Name="treeView1" VerticalAlignment="Top" Width="404" SelectedItemChanged="treeView1_SelectedItemChanged" />
So maybe someone knows how should I implement such functionality?