0

顧客データ用のデータグリッドがあります。私の顧客エンティティには、公開されているメモのコレクションがあります。

メモのステータスに基づいて列に画像を表示する方法が必要です。メモのステータスが「警告」の場合は警告画像を表示し、そうでない場合は通常のステータスの画像を表示します。

これは実行可能ですか?

4

2 に答える 2

0

はい、これを達成する方法は複数あります。

顧客がいる場合はViewModel、特定の顧客がメモコレクションに警告ステータスを持っているかどうかを示すプロパティを公開し、それを使用して画像を表示するかどうかを決定します。

もう1つのオプションはValueConverter、メモコレクションを取り込んで、画像を表示するかどうかを決定するを使用することです。

他のアプローチもあると思いますが、これらは私の頭に浮かんだものです。

于 2013-02-25T19:49:08.100 に答える
0

読み取り専用の[NotMapped]プロパティをCustomerエンティティ(Entity Framework 4を使用)に追加しました。これはブール値を返し、DataGridTemplateColumn内の画像をこれにバインドし、値コンバーターを使用してソースを設定します。

実在物

[NotMapped]
public bool ShowWarning 
{
    get
    {
        if (this.AuditableNotes != null && this.AuditableNotes.Count(an => an.Warning) > 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
}

XAML

<DataGridTemplateColumn
            Header="Status">
    <DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <Image x:Name="MyImage" Source="{Binding ShowWarning, Converter={StaticResource notesStatusConverter}}" Width="25" Height="20"/>
        </DataTemplate>
    </DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>

ValueConverter

public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
    if (value != null && (bool)value == true)
    {
        return "/Assets/Images/symbol_error.png";
    }
    else
    {
        return "/Assets/Images/symbol_information.png";
    }

}
于 2013-02-25T21:29:24.130 に答える