Two ContextMenus at the same time for multi touch
How can I show two ContextMenu
on my window at the same time?
this is my class
public partial class Window1 : Window
{
ContextMenu co开发者_如何学JAVAntextMenu1 = new ContextMenu();
ContextMenu contextMenu2 = new ContextMenu();
public Window1()
{
InitializeComponent();
contextMenu1.Items.Add("Hello1");
contextMenu2.Items.Add("Hello2");
contextMenu1.Placement = System.Windows.Controls.Primitives.PlacementMode.Relative;
contextMenu2.Placement = System.Windows.Controls.Primitives.PlacementMode.Relative;
contextMenu1.PlacementTarget = rectangle1;
contextMenu2.PlacementTarget = rectangle2;
contextMenu1.StaysOpen = true;
contextMenu2.StaysOpen = true;
}
private void button1_Click(object sender, RoutedEventArgs e)
{
contextMenu1.IsOpen = true;
contextMenu2.IsOpen = true;
}
}
Normally a context menu will disappear when clicking somewhere else than in the context menu itself. So having two context menus open at the same time will involve some special handling.
Besides that, this setup will most probably cause the user to be confused.
Perhaps you should consider an other option (toolbar, property panel, cascading context menu)
EDIT
Now that you added your code to the question I am even more worried about this approach. What are you trying to offer to the user? You should simply use Grids or DockPanels instead of rectangles and add regular Menus to them:
<DockPanel Width="200"
Height="200">
<Menu DockPanel.Dock="Top">
<MenuItem Header="Hello1" />
</Menu>
<Grid />
</DockPanel>
<DockPanel Width="200"
Height="200">
<Menu DockPanel.Dock="Top">
<MenuItem Header="Hello2" />
</Menu>
<Grid />
</DockPanel>
</StackPanel>
You can use the Popup control and catch the right-click event to display it.
Unfortunately you'll be starting from scratch and will have to rebuild the context menu, but there will be no problems with having two open at once.
Without knowing alot of Details about you want to do - it is WPF! So you can style everything like you want. You can Display Dialogs/UserControls/Windows on right mouse click and style them like the context menu or however they should look like. With this you have the full control of what you want to display...
精彩评论