VS2010 WPF - Can I create a menu with menu items just via the UI (not editing XAML?)
Just trying to drag my first Menu control onto a WPF appli开发者_如何学Pythoncation 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?
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>
精彩评论