カスタムの方法でデータグリッドの 1 つの列をバインドする際に 1 つの問題があります。だから、私はこのコードを表示しています:
<DataGridTemplateColumn Header="State">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Label Background="" Content="{Binding Path=., Converter={StaticResource measureConv}}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
私のコンバーター:
public class MeasureToStateConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
Measure m;
try
{
m = (Measure)value;
if (m.Value > 100)
{
return "Alarm";
}
}
catch (Exception ex)
{
Debugger.Log(0, "Convertery", "Bład Convertera MeasureToState" + ex.Message);
}
return "Normal";
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
コンテンツと背景のプロパティはカスタムです。コンバーターを使用して、コレクション オブジェクトが何らかの条件を満たしているかどうかを確認し、文字列 YES または NO を返しますが、ある色の背景で文字列フィールドを YES にしたい場合、それが NO の場合は別の色にします。
どうすれば簡単にできますか?2番目のコンバーターの書き込みは少しばかげていると思います。