views:

28

answers:

1

Just trying to drag my first Menu control onto a WPF application in VS2010.

Is there a way to (via the VS2010 UI) setup the menu items etc? Or does one have to jump into the XAML to do this?

Also it seems like the Menu control, after I drag it onto the window, exists at the top of the Window. However I was expecting it to be rendered as a typical Windows menu where it's right at the top associated with the window itself (not the window contents), if that makes sense. Does the VS2010 "menu" item from the toolbox give you the "traditional" windows application menu?

+3  A: 

I would really encourage you to read up on Panels (and Attached Properties) before you start playing with the controls to understand how they are laid out (Especially the difference between Panels and ContentControls is key). In WPF panels decide how the controls are laid out (at least the basics within which controls get a wee say). It sounds much like you are trying to do WPF the WinForms way - and you will end up really frustrated and needing lots of tranquillizers before the hour turns nigh... :)

In the VS Studio the template uses a Grid as the basis for layouting - which by default centers and stretches content (as well as overlaying controls), so just dragging a menu in there will provide insensible designs.

As for jumping into XAML - I never use the ToolBox and the Visual Designer. It's a matter of taste of course, but if you're used to using VS (in contrast to Blend), I find it easier to understand what is happening when I edit the raw XAML.

A few starter resources: link and link. And for a simpler learning environment for getting started - I enjoyed Kaxaml a lot (which is an editor build in XAML/WPF albeit in .Net 3.5 sp1).

EDIT: A small sample - just copy everything between the Window-tags and paste it between the ones in your template that Visual Studio gives you:

<Window ....>
    <DockPanel>
        <Menu DockPanel.Dock="Top">
            <MenuItem Header="_File">
                <MenuItem Header="_Open"/>
                <MenuItem Header="_Save"/>
                <MenuItem Header="_Exit"/>
            </MenuItem>
            <MenuItem Header="_Edit">
                <MenuItem Header="C_ut"/>
                <MenuItem Header="_Copy"/>
                <MenuItem Header="Paste"/>
            </MenuItem>
            <MenuItem Header="Help">
                <MenuItem Header="About"/>
            </MenuItem>
        </Menu>
        <GroupBox Header="Some interesting controls go here">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition/>
                    <ColumnDefinition/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>
                <Label Content="_First property"/>
                <TextBox Grid.Column="1"/>
                <Label Grid.Row="1" Content="_Second property"/>
                <TextBox Grid.Column="1" Grid.Row="1"/>
            </Grid>
        </GroupBox>
    </DockPanel>
</Window>
Goblin
thanks Goblin - you don't know of an example WPF app (with menus) I could open up in VS2010 to take a look? (I'm trying to find one at the moment).
Greg
I'll update my answer with one :)
Goblin
Very much agree. Once you start to grasp the "layout managers" in WPF, you'll never go back to drag 'n drop ala WinForms. I've found the VS 2010 WPF editor has been a nice upgrade to '08. I use the designer only for quick and dirty experimentation now...
Nate
arrr yes - that helps a lot Goblin thanks - so I see you used a DockPanel there
Greg
by the way - so re my question I guess the answer is there is no UI method of building up the menu entries - but rather you have to put them in manually in XAML
Greg
That's usually what I end up with for the outermost container. It's super simple and easy to follow. Some use Grids all over the place as the DockPanel has some issues with tab-navigation as the last control in the DockPanel is set to fill (and thus you'll often have controls docked bottom above the last control - messing up tab-order).
Goblin
To answer your question about designers - if you really want a good UI-designer - go with Blend. Visual Studio's designer is so-so - I find myself adjusting everything afterwards anyways thus eliminating any productivity gains from the visual designer... but glad I could help you get started.
Goblin