开发者

WPF: Show Panel on Right-click

开发者 https://www.devze.com 2022-12-28 15:24 出处:网络
I\'m t开发者_如何学JAVArying to have a WPF ViewBox \'appearing\' at the cursor position in a user control when the user right-clicks on the control. Right now, I have the code:

I'm t开发者_如何学JAVArying to have a WPF ViewBox 'appearing' at the cursor position in a user control when the user right-clicks on the control. Right now, I have the code:

<!-- XAML -->
<Viewbox Width="100" Visibility="Collapsed" x:Name="actionBox">
    <StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch">
        <Button>Item ▼</Button>
        <Button>Permute ▼</Button>
        <Button>Generate ▼</Button>
   </StackPanel>
</Viewbox>

and

/* C# */
private void setPanel_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
{
    Point p = e.GetPosition(this);
    actionBox.Margin = new Thickness(p.X, p.Y, 0, 0);
    actionBox.Visibility = System.Windows.Visibility.Visible;
    actionBox.BringIntoView();
}

The event does get fired, but nothing seems to happen. (The MouseRightButtonDown="..." is in a different part of the XAML file.)

How would one go about writing this in WPF?


Have a look at the Context Menu.

<ContextMenu Name="cm" StaysOpen="true">

                    <MenuItem Header="Item ▼"/>

                    <MenuItem Header="Permute ▼"/>

                    <MenuItem Header="Generate ▼"/>

</ContextMenu>

You can even bind the commands with the menu items as well create submenus.

Fore more information:

http://www.a2zdotnet.com/View.aspx?id=92

0

精彩评论

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