views:

64

answers:

2

Hello,

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!

+1  A: 

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.

abhishek
Thank you abhishek. I was looking for a way to do it graphical in the designer, but seems manually is the best way ):
stefan.at.wpf
+1  A: 

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.

Chad
Thanks for your reply, unfortunately not available using WPF ):
stefan.at.wpf