Click here to Skip to main content
15,880,891 members
Articles / Programming Languages / C#

MVVM (Part 2) - Commanding

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
1 Oct 2010CPOL5 min read 32.3K   278   16  
How to create Commands infrastructure in Silverlight
<UserControl x:Class="HomeGrownMVVM.WelcomePage"
						 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
						 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
						 xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
						 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
						 xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
						 mc:Ignorable="d"
						 d:DesignHeight="300" d:DesignWidth="400"
						 FontSize="14"
						 Loaded="WelcomePage_Loaded"
						 x:Name="WPage"
						 >

	<Grid Background="White" HorizontalAlignment="Stretch">
		<!--Grid definition-->
		<Grid.RowDefinitions>
			<RowDefinition Height="100"></RowDefinition>
			<RowDefinition></RowDefinition>
		</Grid.RowDefinitions>
		<Grid.ColumnDefinitions>
			<ColumnDefinition Width="260" MinWidth="60"></ColumnDefinition>
			<ColumnDefinition></ColumnDefinition>
		</Grid.ColumnDefinitions>
		<!--Grid Splitter-->
		<sdk:GridSplitter Name="gridSplitter1" Width="3"
											VerticalAlignment="Stretch"
											Grid.Column="1" Grid.Row="1"
											Background="Green"
											HorizontalAlignment="Left"/>
		<!--Border that wraps the 'Menu'-->
		<Border BorderBrush="Orange"
						BorderThickness="3"
						Margin="10"
						Grid.Column="0"
						Padding="20"
						Grid.Row="1"
						CornerRadius="15"
						VerticalAlignment="Top"
						>
			<!--The 'Menu' itself-->
			<ListBox BorderThickness="0"
							 ItemsSource="{Binding MenuItemsList}"
							 >
				<ListBox.ItemTemplate>
					<DataTemplate>
						<Border HorizontalAlignment="Stretch"
										Width="180"
										BorderBrush="Gray"
										BorderThickness="{Binding SeparatorThicknes}">
							<HyperlinkButton Content="{Binding DisplayName}"
															 Command="{Binding MenuItemSelectedCommand, ElementName=WPage}"
															 CommandParameter="{Binding}"
															 BorderThickness="0"
															 Foreground="Black"
															 Margin="0"
															 FontWeight="Normal"
															 />
						</Border>
					</DataTemplate>
				</ListBox.ItemTemplate>
			</ListBox>
		</Border>
		<!--Tab Control on the Right-->
		<StackPanel HorizontalAlignment="Stretch"
								VerticalAlignment="Stretch"
								Grid.Column="1"
								Grid.Row="1"
								Margin="5,2"
								Visibility="{Binding ShowViewingArea}"
								>
			<sdk:TabControl Grid.Column="1"
											Grid.Row="1"
											HorizontalContentAlignment="Stretch"
											VerticalContentAlignment="Stretch"
											HorizontalAlignment="Left"
											VerticalAlignment="Top"
											SelectedItem="{Binding TopTabPage, Mode=TwoWay}"
											Margin="4,2,2,2"
											ItemsSource="{Binding TabPagesCollection}"
											>
			</sdk:TabControl>
		</StackPanel>
		<!--Logo-->
		<Border BorderBrush="Pink" 
						BorderThickness="0,0,0,2" 
						Grid.Column="0"
						Grid.ColumnSpan="2"
						Grid.Row="0"
						CornerRadius="0" 
						Padding="1,0, 1,3">
			<StackPanel Orientation="Horizontal" 
									HorizontalAlignment="Stretch"
									Background="WhiteSmoke"
									Grid.Column="0"
									Grid.Row="0"
									Grid.ColumnSpan="2"
									VerticalAlignment="Top">
				<Image 
						Source="Images/mvvm.png"
						HorizontalAlignment="Left"
						VerticalAlignment="Top"
				></Image>
			</StackPanel>
		</Border>
	</Grid>
</UserControl>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions