Click here to Skip to main content
15,896,487 members
Articles / Desktop Programming / WPF

DevForce Code First Walkthrough: From New Project to Running

Rate me:
Please Sign up or sign in to vote.
5.00/5 (6 votes)
2 Dec 2011CPOL8 min read 34.9K   278   18  
This tutorial shows how to build a simple WPF application using Code First in DevForce.
<Window x:Class="CodeFirstWalk.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="800">
    <Window.Resources>
        <DataTemplate x:Key="ProductTemplate">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" MinHeight="30"/>
                    <RowDefinition Height="Auto" MinHeight="30"/>
                    <RowDefinition Height="20" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>

                <TextBlock Text="Product: " Grid.Row="0" Grid.Column="0" 
                       VerticalAlignment="Center" />
                <TextBlock Text="{Binding ProductId}" Grid.Row="0" Grid.Column="1" 
                       VerticalAlignment="Center" Margin="2,0,2,0" MinWidth="20"/>
                <TextBox Text="{Binding ProductName, Mode=TwoWay, ValidatesOnDataErrors=True}" 
                     Grid.Row="0" Grid.Column="2" 
                     VerticalAlignment="Center" Margin="2,0,2,0" MinWidth="100"/>
                <TextBlock Text="NotPersisted: " Grid.Row="0" Grid.Column="3" 
                       VerticalAlignment="Center" Margin="8,2,0,0"/>
                <TextBox Text="{Binding NotPersisted, Mode=TwoWay, ValidatesOnDataErrors=True}" 
                     Grid.Row="0" Grid.Column="4"
                     VerticalAlignment="Center" MinWidth="100"/>
                <TextBlock Text="{Binding EntityAspect.EntityState}" Grid.Row="0" Grid.Column="5"
                       VerticalAlignment="Center" Margin="8,0,0,0"/>

                <TextBlock Text="Category: " Grid.Row="1" Grid.Column="0" 
                       VerticalAlignment="Center" Margin="8,0,0,0"/>
                <TextBlock Text="{Binding CategoryId}" Grid.Row="1" Grid.Column="1" 
                       VerticalAlignment="Center" Margin="2,0,2,0" MinWidth="20"/>
                <TextBox Text="{Binding Category.CategoryName, Mode=TwoWay, ValidatesOnDataErrors=True}" 
                     Grid.Row="1" Grid.Column="2"
                     VerticalAlignment="Center" Grid.ColumnSpan="4" />

                <TextBlock Text="Supplier: " Grid.Row="2" Grid.Column="0" 
                       VerticalAlignment="Center" Margin="8,0,0,0" />
                <TextBox Text="{Binding Supplier.CompanyName, Mode=TwoWay, ValidatesOnDataErrors=True}" 
                     Grid.Row="2" Grid.Column="2" 
                     VerticalAlignment="Center" Grid.ColumnSpan="4"/>
            </Grid>
        </DataTemplate>

    </Window.Resources>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="40" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <TextBlock Text="Code First Walk in WPF" FontSize="20" TextAlignment="Center" VerticalAlignment="Center" />
        <ListBox x:Name="messages" Grid.Row="1" ItemsSource="{Binding Messages}" />
        <GridSplitter Grid.Row="2" HorizontalAlignment="Stretch"  VerticalAlignment="Top" Height="8" />
        <ListBox x:Name="productsListBox" Grid.Row="2" Margin="0,10,0,0"
                  SelectedItem="{Binding SelectedProduct, Mode=TwoWay}"
                  ItemsSource="{Binding Products}"
                  ItemTemplate="{StaticResource ProductTemplate}"/>
        <StackPanel Grid.Row="3" Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
            <Button x:Name="AddButton"  MinWidth="40" Margin="0,2,8,2" Click="AddButton_Click">Add</Button>
            <Button x:Name="DeleteButton" MinWidth="40" Margin="0,2,8,2" Click="DeleteButton_Click">Delete</Button>
            <Button x:Name="SaveButton" MinWidth="40" Margin="0,2,8,2" Click="SaveButton_Click">Save</Button>
        </StackPanel>
    </Grid>
</Window>

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