You need to expose the new game list view model to the user. Try it yourself before reading on.

Got it? Good. Add a UserControl to Lesson.Client and name it "GameListControl". Add the opponent text box, the Challenge button, and the list of active games.
<UserControl
    x:Class="Lesson.Client.GameListControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <StackPanel>
        <TextBox
            Width="120"
            Text="{Binding Opponent, UpdateSourceTrigger=PropertyChanged}" />
        <Button
            Command="{Binding Challenge}">Challenge</Button>
        <ListBox
            ItemsSource="{Binding ActiveGames}" />
    </StackPanel>
</UserControl>
Add this control to the main window.
<DockPanel>
    <local:LogOnControl
        DockPanel.Dock="Top"
        DataContext="{Binding MachineVM}" />
    <local:GameListControl
        DockPanel.Dock="Left"
        DataContext="{Binding GameListVM}" />
    <TextBox />
</DockPanel>
Then add the GaleListVM property to the main view model.
private GameListNavigationModel _gameListNavigationModel = new GameListNavigationModel();

public GameListViewModel GameListVM
{
    get
    {
        LogOn currentLogOn = _machine.LogOns.FirstOrDefault();
        return currentLogOn == null
            ? null
            :  new GameListViewModel(currentLogOn.User, _gameListNavigationModel);
    }
}
Run it and see how it behaves. You can log on and add a game, but it doesn't properly display the opponent's name. Add an item template to fix that.
<ListBox
    ItemsSource="{Binding ActiveGames}">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <TextBlock
                Text="{Binding OpponentName}" />
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>
Now it looks right. You'll need to use your designer and XAML skills to make it look good.

Next: Lesson 3a: Negative facts

Last edited Aug 8, 2010 at 4:35 PM by MichaelLPerry1971, version 2

Comments

No comments yet.