简体   繁体   中英

Create a context menu using VS 2010 designer?

I need to create a context menu, is it possible to do this using the VS 2010 designer / see a preview while writing your xaml code? Thanks for any hint!

I dont use VS Designer view. I always prefer to write my XAML myself. ContextMenu is very easy to create. You just need to create a contextmenu as staticResource or directly into the property contextmenu.

<ContextMenu>
            <MenuItem Command="Cut">
                <MenuItem.Icon>
                    <Image Source="Images/cut.png" />
                </MenuItem.Icon>
            </MenuItem>
            <MenuItem Command="Copy">
                <MenuItem.Icon>
                    <Image Source="Images/copy.png" />
                </MenuItem.Icon>
            </MenuItem>
            <MenuItem Command="Paste">
                <MenuItem.Icon>
                    <Image Source="Images/paste.png" />
                </MenuItem.Icon>
            </MenuItem>
        </ContextMenu>

You can also create contextmenu dynamically using code.

MenuItem mnu = new MenuItem();
mnu.Header = "Paste";
contextmenu.Items.Add(mnu);

I hope this will help you.

I'm not sure about WPF/XAML, but in WinForms you can drag a ContextMenu onto the designer to edit it. Look for the ContextMenu in your Toolbox.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM