Listing 2: XAML • WPF Does Windows

Windows are the WPF equivalent to Forms. They can provide menus and toolbars and contain entity specifc user controls. Command bindings connect user interface elements that initiate an action with the code for the action and code that indicates when the elements should be enabled.

<Window x:Class="Startup"
	xmlns=
	"http://schemas.microsoft.com/winfx/2006/xaml/
	presentation"
	xmlns:x=
	"http://schemas.microsoft.com/winfx/2006/xaml"
	Title="TestApp" Height="545" Width="560" >
	<Window.CommandBindings>
		<CommandBinding 
			Command="ApplicationCommands.Save"
			Executed="SaveCommandExecuted"
			CanExecute="SaveCommandCanExecute"/>
		<CommandBinding 
			Command="ApplicationCommands.Close"
			Executed="CloseCommandExecuted"
			CanExecute="CloseCommandCanExecute"/>
	</Window.CommandBindings>
	<Grid Name="MainGrid">
		<Grid.RowDefinitions>
			<RowDefinition Height="Auto"/>
			<RowDefinition/>
	</Grid.RowDefinitions>
	<Grid.ColumnDefinitions/>
	<Rectangle Fill=
		"{StaticResource HorizontalGradientBrush}"/>
	<Menu>
		<MenuItem Header="File">
		<MenuItem Header="Save" 
			Command="ApplicationCommands.Save"/>
		<Separator/>
		<MenuItem Header="Exit" 
			Command="ApplicationCommands.Close"/>
		</MenuItem>
		<MenuItem Header="View">
		<MenuItem Header="Customer" 
			Click="CustomerClick"/>
		<MenuItem Header="Incidents" 
			Click="IncidentClick"/>
		</MenuItem>
		<MenuItem Header="Fun">
		<MenuItem Header="Fun Stuff" 
			Click="­FunStuffClick"/>
		</MenuItem>
		</Menu>
	</Grid>
</Window>
comments powered by Disqus
Upcoming Events

.NET Insight

Sign up for our newsletter.

I agree to this site's Privacy Policy.