我目前有 2 个包含不同类别的列表:List<Player>
and List<Monster>
.
I want to get these two lists in a single Datagrid as follows:
我需要它们位于一个数据网格中的原因是我需要对主动性进行排序,并显示从高到低的顺序。数据网格还需要与任意数量的玩家/怪物一起工作。这些类如下所示:
public partial class Player
{
public bool IsInParty { get; set; }
public string Name { get; set; }
public int Ac { get; set; }
public string ArmorType { get; set; }
public string[] Speed { get; set; }
public int InitiativeBonus { get; set; }
public string[] DmgVul { get; set; }
public string[] DmgRes { get; set; }
public string[] DmgImm { get; set; }
public string[] CondImm { get; set; }
public string[] Senses { get; set; }
public string[] Languages { get; set; }
public NameValuePair[] Conditions { get; set; }
public int Id { get; set; }
}
public partial class Monster
{
public BaseMonster Stats { get; set; }
public int Id { get; set; }
public string Name { get; set; }
public int Hp { get; set; }
public List<int> Damage { get; set; }
public bool IsOverhealed => Hp > Stats.MaxHp;
public bool IsBloody => Hp <= Stats.MaxHp / 2.0;
public bool IsNearDeath => Hp <= Stats.MaxHp / 4.0;
public bool IsDead => Hp <= 0;
public List<NameValuePair> Conditions { get; set; }
}
public partial class BaseMonster
{
public int DefaultId { get; set; }
public string DefaultName { get; set; }
public string Type { get; set; }
public string Alignment { get; set; }
public int Ac { get; set; }
public string ArmorType { get; set; }
public int MaxHp { get; set; }
public string HitDice { get; set; }
public string[] Speed { get; set; }
public int Str { get; set; }
public int Dex { get; set; }
public int Con { get; set; }
public int Int { get; set; }
public int Wis { get; set; }
public int Cha { get; set; }
public string[] SavThrProf { get; set; }
public string[] SkillProf { get; set; }
public string[] DmgVul { get; set; }
public string[] DmgRes { get; set; }
public string[] DmgImm { get; set; }
public string[] CondImm { get; set; }
public string[] Senses { get; set; }
public string[] Languages { get; set; }
public string Challenge { get; set; }
public NameValuePair[] Traits { get; set; }
public NameValuePair[] Actions { get; set; }
public NameValuePair[] LegendaryActions { get; set; }
public string LairActions { get; set; }
public string RegionalEffects { get; set; }
}
因为我对前端和xaml比较陌生,所以我在如何处理这个问题上遇到了一些麻烦。目前我已经通过一些测试数据成功获得以下内容:
<Grid Grid.Row="2" Grid.Column="1">
<DataGrid x:Name="creatureDatagrid">
<DataGrid.Columns>
<DataGridTextColumn Header="Name" Binding="{Binding Name}"/>
<DataGridTextColumn Header="ID" Binding="{Binding Id}"/>
<DataGridTextColumn Header="AC" Binding="{Binding Ac}"/>
<DataGridTextColumn Header="HP" Binding="{Binding Hp}"/>
</DataGrid.Columns>
</DataGrid>
<Grid/>
正如您所看到的,某些值工作正常,但在这种情况下 AC 不起作用,因为 AC in 发现BaseMonster
in the Monster
class