1

在这里,我有一种填充消息字段的方法

   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 我也想同时看到直接和空值。目前它不显示空值。有人可以帮我理解我做错了什么吗?

4

2 回答 2

1

我刚刚发现查询出了什么问题这是我应该做的

    MappingRule = transactionRuleList.Any(mapRule => mapRule.SourceElementId == msgFields.Id)
                          ?transactionRuleList.First(mapRule => mapRule.SourceElementId == msgFields.Id).MappingRule:"NULL"
于 2013-06-09T20:44:38.697 回答
0

好的,现在我想我明白了。MappingRule 类声明是什么样的?如果您想在 MappingRule 中显示“direct”或“null”,您的绑定必须与存储它的属性挂钩。

例如,如果“直接”存储在 MappingRule 的 Type 属性中,则您的绑定必须在 MappingRule.Type 上,而不是 MappingRule。

也许这有帮助?

于 2013-06-07T14:58:42.027 回答