Click here to Skip to main content
15,884,388 members
Articles / Web Development / ASP.NET

Presentation Model in Action

Rate me:
Please Sign up or sign in to vote.
4.93/5 (31 votes)
3 Feb 2008CPOL14 min read 124.5K   1.6K   119  
Use the Presentation Model pattern in ASP.NET Web site, Windows Forms and WPF
<UserControl x:Class="Demo.WpfApp.CustomerList"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:Demo.WpfApp">
    <UserControl.Resources>
        <ObjectDataProvider x:Key="controller" ObjectType="{x:Type local:CustomerPresentationModel}" MethodName="get_Instance" />
    </UserControl.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="30"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <DockPanel Grid.Row="0" LastChildFill="False">
            <TextBlock VerticalAlignment="Center" DockPanel.Dock="Right" Margin="5,0,10,0" Text="{Binding Source={StaticResource controller}, Path=ItemCount}"/>		        
            <TextBlock VerticalAlignment="Center" DockPanel.Dock="Right" Margin="5,0,0,0" Text="Number of items found:"/>
            <TextBlock VerticalAlignment="Center" DockPanel.Dock="Left" Margin="5,0,0,0" Text="Search:"/>
            <TextBox VerticalAlignment="Center" DockPanel.Dock="Left" Margin="5,0,0,0" Width="200" Name="txtSearch" TextChanged="TextBox_TextChanged" />
        </DockPanel>

        <ListView 
            Grid.Row="1" Grid.Column="0" 
            x:Name="ListView"
            ItemsSource="{Binding Source={StaticResource controller},Path=Items}"
            ScrollViewer.CanContentScroll="True"
            SelectionMode="Single" SelectionChanged="ListView_SelectionChanged">
            <ListView.View>
                <GridView>
                    <GridViewColumn Header="Name" Width="180"
                         DisplayMemberBinding="{Binding Path=Name}"/>
                    <GridViewColumn Header="Address" Width="320"
                         DisplayMemberBinding="{Binding Path=Address}"/>
                    <GridViewColumn Header="Comments" Width="180"
                         DisplayMemberBinding="{Binding Path=Comments}"/>
                </GridView>
            </ListView.View>
        </ListView>
    </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
Architect
Canada Canada
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions