Simple MVVM application
In this recipe, we will cover the basic principles of MVVM by creating a simple Phone 7 application with ViewModel and sample data.
Getting ready
Let's create a new Phone 7 Project with a project name Recipe1_SimpleMVVM
and a solution name Ch8_Recipes
.
How to do it...
Here we will create a simple user interface with a list box to display text in two TextBlock
controls. Then, we will add the ViewModel
class, which returns data from the sample data.
Open
MainPage.xaml
and change theApplicationTitle
andPageTitle
:<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28"> <TextBlock x:Name="ApplicationTitle" Text="Data Recipes" Style="{StaticResource PhoneTextNormalStyle}"/> <TextBlock x:Name="PageTitle" Text="Simple MVVM" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/> </StackPanel>
Add two
TextBlock
controls as shown in the following code snippet. We will be using one forTaskName
and the other forTaskNotes
:<Grid x...