This project is read-only.

Table of Squares Sample

Remember your Computer Science 101 Class? Remember the "Table of Squares"? Maybe it was in C? Or ... Fortran? Jump ahead to the modern era with markup programming. This sample shows the beautiful simplicity of iterators, collections, and anonymous object initializers for sample data. Forget the fancy stuff; I love sample data!

Here's what the app looks like even in the designer. Sample data in the designer means you can actually see the fonts and foreground colors, etc without running the program.

    Height="300" Width="300">
        <p:ResourceObject x:Key="ViewModel">
            <p:Property Prop="Table">
                    <p:For Var="i" Value="0" UpperLimit="5" Increment="1">
                                <p:Property Prop="Number" Path="$i"/>
                                <p:Property Prop="Square" Path="$i * $i"/>
                                <p:Property Prop="Sqrt" Path="[Math].Sqrt($i)"/>
    <Grid DataContext="{StaticResource ViewModel}">
            <ListView ItemsSource="{Binding Table}">
                        <GridViewColumn DisplayMemberBinding="{Binding Number}"/>
                        <GridViewColumn DisplayMemberBinding="{Binding Square}"/>
                        <GridViewColumn DisplayMemberBinding="{Binding Sqrt}"/>
            <DataGrid ItemsSource="{Binding Table}"/>

Look, ma! No, classes! Waddya know, DataGrid even auto-generated the columns. Markup programming's collections default to smart observable generic typed collections that work out-of-the-box with item sources and list views like ListBox and DataGrid.


Last edited Mar 31, 2011 at 7:27 AM by jrs, version 23


No comments yet.