在这里,我有一种填充消息字段的方法
public List<MessageFieldViewModel> GetAllViewModelMsgFields()
{
messageFieldVModel = messageField.GetAllMessageField().Select(msgFields => new MessageFieldViewModel
{
Id = msgFields.Id,
Code = msgFields.Code,
Name = msgFields.Name,
Position = msgFields.Position,
Length = msgFields.Length,
IsMapped = (transactionRuleList.Any(tr => tr.SourceElementId == msgFields.Id)),
MappingRule = transactionRuleList.Any(mapRule => mapRule.SourceElementId
== msgFields.Id)?
transactionRuleList.First(mapRule => mapRule.SourceElementId
== msgFields.Id).MappingRule
: null
})
.ToList();
return messageFieldVModel;
}
在我的网格上,我想显示所有值:
<DataGrid ItemsSource="{Binding MessageFields}" Margin="4,0,380,6" Grid.Row="2" AutoGenerateColumns="False" IsReadOnly="True">
<DataGrid.Columns>
<DataGridTextColumn Header="ID" Binding="{Binding Id}" />
<DataGridTextColumn Header="Code" Binding="{Binding Code}" />
<DataGridTextColumn Header="Field Name" Binding="{Binding Name}"/>
<DataGridTextColumn Header="Position" Binding="{Binding Position}" />
<DataGridTextColumn Header="Length" Binding="{Binding Length}" />
<DataGridTemplateColumn Header="IsMapped">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<CheckBox IsChecked="{Binding Path=IsMapped}"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Header="MappingRule" Binding="{Binding MappingRule}" />
</DataGrid.Columns>
</DataGrid>
// 一些 MessageField 数据
MessageField.Add(new MessageFieldModel(01, "GMSLEN", "MESSAGE LENGTH", 5, 4));
MessageField.Add(new MessageFieldModel(01, "GMSDST", "MESSAGE DESTINATION", 9, 7));
MessageField.Add(new MessageFieldModel(011, "GMSOR", "MESSAGE ORIGIN", 16, 7));
MessageField.Add(new MessageFieldModel(02, "GMSLEN", "MESSAGE LENGTH", 5, 4));
MessageField.Add(new MessageFieldModel(02, "GMSDST", "MESSAGE DESTINATION", 9, 7));
MessageField.Add(new MessageFieldModel(012, "GMSOR", "MESSAGE ORIGIN", 16, 7));
// 一些翻译规则数据
TranslationRule.Add(new TranslationRuleModel(01, 01, 690, "direct"));
TranslationRule.Add(new TranslationRuleModel(01, 01, 690, null));
TranslationRule.Add(new TranslationRuleModel(02, 02, 690, "direct"));
TranslationRule.Add(new TranslationRuleModel(02, 02, 690, null));
TranslationRule.Add(new TranslationRuleModel(03, 03, 690, "direct"));
TranslationRule.Add(new TranslationRuleModel(03, 03, 690, null));
现在我的网格正在显示 IsMapped 的值,但对于 MappingRule 我也想同时看到直接和空值。目前它不显示空值。有人可以帮我理解我做错了什么吗?