Hi,
maybe someone can help me... I have a XamDataTree with an custom NodeLayout.ItemTemplate, including StackPanel with TextBlock and a Contextmenu on the Stackpanel. The Contextmenu is bind to an ObservableCollection in my View. Sometimes it can happen that the collection is empty, for this reason i included an style:
<ContextMenu.Style> <Style TargetType="{x:Type ContextMenu}"> <Style.Triggers> <Trigger Property="HasItems" Value="False"> <Setter Property="Visibility" Value="Collapsed" /> </Trigger> </Style.Triggers> </Style></ContextMenu.Style>
Works fine!
But after collapse and expand one of the parent nodes, some empty white boxes appears.
On the left side its a normal TreeView, with the same style => no problems
On the right side the XamDataTree, after right clicking some nodes and the collapse and expand.
I'm using Infragistics WPF 2015.1
Sample Application is attached.
Hi Florian,
Awesome! That's pretty much the same code I used.
If you don't want any code-behind you can probably create a Behavior<T> or an attached property which attaches to the StackPanel and handles the Unloaded event in there.
Hi Rob,
thanks, problem is fixed now. :)
Here is the solution:
<StackPanel Orientation="Horizontal" Tag="{Binding DataContext, RelativeSource={RelativeSource AncestorType={x:Type ig:XamDataTree}}}" Unloaded="StackPanel_Unloaded">private void StackPanel_Unloaded(object sender, RoutedEventArgs e){ StackPanel panel = sender as StackPanel; if (panel != null) { panel.ContextMenu = null; }}
The reason why the style works with the TreeView is because the TreeView is not re-creating the DataTemplate content every time the node is collapsed and then expanded. Each node uses the same instance of the content. The XamDataTree on the other hand is recreating the content each time you collapse -> expand the node. This causes a new ContextMenu to get created and I think it is the old context menu that is left behind when you collapse -> expand. In order to resolve this you will need to get rid of the old ContextMenu when the data template content is unloaded. For this you can handle the Unloaded event and then set the ContextMenu property to null.