I was playing with the samples.
One of the basic requirements is to be able to support context menus.
I did not see any examples with context menus. So I tried modifying the following, in the datadrilldown.xaml sample:
<TextBlock Grid.Column="1" x:Name="TextBlockRevenue" FontWeight="Bold" TextWrapping="Wrap" DataContext="{TemplateBinding DataContext}" Text="{Binding Path=Revenue, StringFormat='{}{0:C}'}" > <TextBlock.ContextMenu> <ContextMenu> <MenuItem Header="My ConextMenu">Foo_0</MenuItem>
</ContextMenu> </TextBlock.ContextMenu> </TextBlock>
I also added the following
<ig:XamTreemap.NodeBinders> <ig:NodeBinder TargetTypeName="Manufacturer" ValuePath="Revenue" TextPath="Name" ItemsSourcePath="Products" NodeStyle="{StaticResource ManufacturerNodeStyle}" > <ig:NodeBinder.ContextMenu> <ContextMenu IsEnabled="True" AllowDrop="True"> <ContextMenu.Items> <MenuItem Header="My New ContextMenu">Foo_1</MenuItem> </ContextMenu.Items> </ContextMenu> </ig:NodeBinder.ContextMenu> </ig:NodeBinder>
When I run the application, right-mouse-button click will not display the context menu.The intellisense shows that the object.ContextMenu is understood and the xaml compiles. it just does not display at runtime.
It would have been great if the treeMap examples also included some context menu sample.Would it be possible to get a simple complete example, ideally using the MVVM pattern.
Thank
Currently silverlight does not support a standart way to show context menus. You may try using our xamContextMenu control.
thanks for your reply.
I am not using the silverlight version/.
I'm analyzing the viability of using the WPF version. Does this change the answer?Thanks
In wpf you could handle the mouse right button down event and do something like this
void treemap_NodeMouseRightButtonDown(object sender, TreemapNodeClickEventArgs e)
{
e.Node.ContextMenu = new ContextMenu();
e.Node.ContextMenu.Items.Add(new MenuItem() { Header = "Menu1" });
e.Node.ContextMenu.Items.Add(new MenuItem() { Header = "Menu2" });
e.Node.ContextMenu.Items.Add(new MenuItem() { Header = "Menu3" });
e.Node.ContextMenu.IsOpen = true;
}
When we are building the context menus, we would like to enable or disable the menuitem depending on whether it is the childmost visible node. How can I tell if the e.Node argument is the child most visible node?
Thanks
By "child most visible node", do you mean the opacity of the node, or if it is a leaf node (at the bottom of the hierarchy)?
If the context menu depends on the type of the node (for instance Customer or Product), you can do the following: if(e.Node.DataContext is Customer) { ...build a cutomer context menu...}.
If the case is the one with the opacity, there are several solutions. If the opacity values are predefined (lets say 50 or 70), you can get the opacity of the node and build a menu according to it. But if the "most visible" is determined by the surronding neighbour nodes, things are getting complex.
I mean that the context menu will be shown only for the topmost node at the point of the click - at this point there are more nodes underneath. So if a mouse right button up is fired for all the nodes underneath several context menus would be popped up.
> It will also be shown only for the topmost element which is clicked. This is not necessarily the desired behaviour.
In general, I think context menus should always be displayed, irrespective of the selected node. But the enabled state of certain menu items may depend on the properties of the selected node. We have this requirement.
Now we are working on a fix of the problem that one cannot specfy context menu in the xaml of the node template. The reason is that we handle the mouse right button up and the context menu does not show. Hope that in the next service release or release you will be able add context menus easier. It will also be shown only for the topmost element which is clicked.