Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Catel - Part 3 of n: The MVVM Framework

, 28 Jan 2011 CPOL
This article explains the MVVM framework that ships with Catel.
catel-03_01-mvvm-framework.zip
Catel.Articles.Base.dll
Catel.Core.dll
Catel.Windows.dll
log4net.dll
Examples
BasicViewModel
DataWindow
Catel.Articles.03 - MVVM.exe
ControlToViewModelWithWindow
ControlToViewModelWithControl
Microsoft.Practices.Unity.dll
System.Windows.Interactivity.dll
catel-03_01-mvvmframework.zip
Catel.Articles.Base.dll
Catel.Core.dll
Catel.Windows.dll
log4net.dll
Catel.Articles.03 - MVVM.exe
Code-behind:
------------

/// <summary>
/// Interaction logic for PersonWindow.xaml
/// </summary>
public partial class PersonWindow : DataWindow<PersonViewModel>
{
    /// <summary>
    /// Initializes a new instance of the <see cref="PersonWindow"/> class.
    /// </summary>
    /// <param name="viewModel">The view model.</param>
    public PersonWindow(PersonViewModel viewModel)
        : base(viewModel)
    {
        // Initialize component
        InitializeComponent();
    }
}

===========================================================

Xaml:
-----

<Windows:DataWindow x:Class="Catel.Articles._03___MVVM.Examples.DataWindow.PersonWindow"
                    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:BasicViewModel="clr-namespace:Catel.Articles._03___MVVM.Examples.BasicViewModel"
                    xmlns:Windows="clr-namespace:Catel.Windows;assembly=Catel.Windows"
                    xmlns:Controls="clr-namespace:Catel.Windows.Controls;assembly=Catel.Windows"
                    xmlns:Models="clr-namespace:Catel.Articles._03___MVVM.Models"
                    xmlns:Converters="clr-namespace:Catel.Articles._03___MVVM.UI.Data.Converters"
                    x:TypeArguments="BasicViewModel:PersonViewModel" MaxWidth="400" MaxHeight="300">

    <!-- Resources -->
    <Windows:DataWindow.Resources>
        <!-- Converters -->
        <Converters:GenderToIsSelectedConverter x:Key="GenderToIsSelectedConverter" />
    </Windows:DataWindow.Resources>

    <!-- Content -->
    <Controls:StackGrid>
        <!-- Row definitions -->
        <Controls:StackGrid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
        </Controls:StackGrid.RowDefinitions>

        <!-- Column definitions -->
        <Controls:StackGrid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="*" />
        </Controls:StackGrid.ColumnDefinitions>

        <!-- Gender -->
        <Label Content="Gender" />
        <StackPanel Orientation="Horizontal" x:Name="genderStackPanel">
            <RadioButton Content="Male" IsChecked="{Binding Gender, Converter={StaticResource GenderToIsSelectedConverter}, ConverterParameter={x:Static Models:Gender.Male}, ValidatesOnDataErrors=True, NotifyOnValidationError=True}" 
                         Validation.ValidationAdornerSiteFor="{Binding ElementName=genderStackPanel}" />
            <RadioButton Content="Female" IsChecked="{Binding Gender, Converter={StaticResource GenderToIsSelectedConverter}, ConverterParameter={x:Static Models:Gender.Female}, ValidatesOnDataErrors=True, NotifyOnValidationError=True}" 
                         Validation.ValidationAdornerSiteFor="{Binding ElementName=genderStackPanel}" />
        </StackPanel>

        <!-- First name -->
        <Label Content="First name" />
        <TextBox Text="{Binding FirstName, ValidatesOnDataErrors=True, NotifyOnValidationError=True}" />

        <!-- Middle name -->
        <Label Content="Middle name" />
        <TextBox Text="{Binding MiddleName, ValidatesOnDataErrors=True, NotifyOnValidationError=True}" />

        <!-- Last name -->
        <Label Content="Last name" />
        <TextBox Text="{Binding LastName, ValidatesOnDataErrors=True, NotifyOnValidationError=True}" />
    </Controls:StackGrid>
</Windows:DataWindow>

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)

Share

About the Author

Geert van Horrik
Software Developer CatenaLogic
Netherlands Netherlands
I am Geert van Horrik, and I have studied Computer Science in the Netherlands.
 
I love to write software using .NET (especially the combination of WPF and C#). I am also the lead developer of Catel, an open-source application development framework for WPF, Silverlight, WP7 and WinRT with the focus on MVVM.
 
I have my own company since January 1st 2007, called CatenaLogic. This company develops commercial and non-commercial software.
 
To download (or buy) applications I have written, visit my website: http://www.catenalogic.com
Follow on   Twitter

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.141223.1 | Last Updated 28 Jan 2011
Article Copyright 2010 by Geert van Horrik
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid