views:

669

answers:

0

Calling all WPF experts!

I'm converting an application I made to create characters for a particular RPG from Window Forms to WPF. For the most part, the program is much simpler in its WPF form; however, I can't seem to figure this part out for the life of me.

I have a database that contains a list of skills that the character can take. This database is exclusive from the characters -- updating the characters won't change the database. The user can add new skills to the database if they want, but this is separate from character creation. In the character creation window, I have a ListView to show the skills listed in the database. Clicking on a row in the ListView updates a description textbox and the Image control -- this all works fine.

The character is stored in a character class; which contains a list of skills that the character has taken. This list does not contain all of the skills in the database, so the user can trade that character between applications with modified databases without issue.

I want to display some fields from the character class, and some fields from the database in the same ListView. For example,

Name(database), Level(character), Score(character), MaxTakenCount(database)

What I want to achieve: The character's skill list will have zero skills until the user raises the 'Level' value to a value greater than one. Changing the 'Level' will create an instance of that skill and stores it in the character's skill list. The score is calculated using a formula stored in the database for that skill (same table as Name, MaxTakenCount). Setting the 'Level' back to zero removes the skill from the character's skill list. With any luck, the values would be two way databound, so I can use undo/redo. (Undo queue stores serialized copies of the character object whenever a change is made.)

How possible is this WPF? I have no idea on how to juggle the database row and the character's skill list to do what I want. Here is what I have so far. Note: the Score and Level bindings don't work since I don't know how to properly reference the skill list. The skill list is the data context of the tab that contains the ListView. The ListView's ItemSource is set to the SkillTable behind the scenes.

 <ListView Name="listSkills" Margin="10" Grid.Row="2" IsSynchronizedWithCurrentItem="True" Background="#AAFFFFFF" FontSize="14">
    <ListView.View>
        <GridView>
            <GridViewColumn Header="Name">
                <GridViewColumn.CellTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding Name, Mode=TwoWay}" Margin="5" />
                    </DataTemplate>
                </GridViewColumn.CellTemplate>
            </GridViewColumn>
            <GridViewColumn Header="Score">
                <GridViewColumn.CellTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding Score, Mode=TwoWay}" Margin="5" />
                    </DataTemplate>
                </GridViewColumn.CellTemplate>
            </GridViewColumn>
            <GridViewColumn Header="Level">
                <GridViewColumn.CellTemplate>
                    <DataTemplate>
                        <ListBox SelectedIndex="{Binding Level, Mode=TwoWay}">
                            <ListBox.Style>
                                <Style TargetType="ListBox">
                                    <Setter Property="ItemsPanel">
                                        <Setter.Value>
                                            <ItemsPanelTemplate>
                                                <StackPanel Orientation="Horizontal" Margin="5,0" HorizontalAlignment="Left" />
                                            </ItemsPanelTemplate>
                                        </Setter.Value>
                                    </Setter>
                                </Style>
                            </ListBox.Style>
                            <ListBoxItem Width="15"> </ListBoxItem>
                            <ListBoxItem Width="15">S</ListBoxItem>
                            <ListBoxItem Width="15">T</ListBoxItem>
                            <ListBoxItem Width="15">M</ListBoxItem>
                        </ListBox>
                    </DataTemplate>
                </GridViewColumn.CellTemplate>
            </GridViewColumn>
        </GridView>
    </ListView.View>
</ListView>

The ListView is populated with every row in the database. The database columns are properly populated; however, the character fields are not. Please help this WPF newbie!!