調用所有WPF專家!WPF:使用多個來源綁定ListView
我正在將一個應用程序創建爲從窗體窗體到WPF的特定RPG。在大多數情況下,該程序的WPF格式更簡單;然而,我似乎無法將這部分視爲我生命中的一部分。
我有一個數據庫,其中包含角色可以採用的技能列表。這個數據庫是從字符中排除的 - 更新字符不會改變數據庫。用戶可以根據需要向數據庫添加新技能,但這與角色創建是分開的。在角色創建窗口中,我有一個ListView來顯示數據庫中列出的技能。點擊ListView中的一行可以更新描述文本框和圖像控件 - 這一切都可以正常工作。
該字符存儲在一個字符類中;其中包含角色所擁有的技能列表。該列表不包含數據庫中的所有技能,因此用戶可以在修改數據庫的應用程序之間交換該字符而不會出現問題。
我想在字符類中顯示一些字段,並在同一個ListView中顯示數據庫中的一些字段。例如,
名稱(數據庫),級(人物),得分(性格),MaxTakenCount(數據庫)
我想達到的目標: 人物的技能列表將具有零級的技能,直到用戶提高了'級別'值設置爲大於1的值。更改'等級'將創建該技能的一個實例並將其存儲在角色的技能列表中。分數是使用存儲在數據庫中的該技能的公式(與名稱MaxTakenCount相同的表格)計算的。將'等級'設置回零可以從角色的技能列表中刪除技能。有幸運的是,這些值將是雙向數據綁定,所以我可以使用撤銷/重做。 (撤消隊列存儲字符對象的序列化副本,每當發生更改時)。
此WPF有多可能?我不知道如何處理數據庫行和角色的技能列表來做我想做的事情。這是我到目前爲止。注意:Score和Level綁定不起作用,因爲我不知道如何正確引用技能列表。技能列表是包含ListView的選項卡的數據上下文。 ListView的ItemSource在幕後設置爲SkillTable。
<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>
ListView填充數據庫中的每一行。數據庫列正確填充;但是,字符字段不是。請幫助這個WPF新手!