現在、次のメソッドを使用して、行の背景の色を設定しています。C#/ WPF - DataGrid - タイムアウト後の要素の色の更新
XAML
<Style TargetType="{x:Type xcdg:DataRow}">
<Setter Property="Background">
<Setter.Value>
<MultiBinding Converter="{StaticResource colorConverter}">
<Binding RelativeSource="{RelativeSource Self}" Path="IsSelected"/>
<Binding BindsDirectlyToSource="True" />
</MultiBinding>
</Setter.Value>
</Setter>
</Style>
C#
public class ColourConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
var isRowSelected = (bool)values[0];
var myInstance = (MyClass) values[1];
// Return default
if (isRowSelected || myInstance == null)
return DependencyProperty.UnsetValue;
// Get the check for the current field
return GetColour(myInstance) ?? DependencyProperty.UnsetValue;
}
private static SolidColorBrush GetColour(MyClass myInstance)
{
if (heartbeat == null)
{
return null;
}
// Is it more two minutes old?
return (myInstance.CreatedDateTime + TimeSpan.FromMinutes(2) < Clock.UtcNow())
? Brushes.LightPink
: Brushes.LightGreen;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException(this.GetType().Name + " cannot convert back");
}
}
問題は、このコンバータは、新しい値のみでのDataRowの人口で呼び出されていることです。私が本当に必要とするのは、一定時間後に色を変更するか、Converterを定期的に再評価させるコールバックです。
色の更新は瞬時に行う必要はありませんが、わずか数秒で完了します。私は各行のコールバックを持っている場合、私は効率的なオプションのように見えない~1000行で、(それらは作成され、したがって(色が変わる)色が変わる)一致する数のスレッドが必要です。
もう1つの方法は、1つのスレッドの行を定期的にポーリングし、各繰り返しでコンバータを再評価することです(5秒ごとに?)。私はこれが行く可能性が高い方法だと思うが、私はWPFでそれについてどうやって行くのか分からない。
おそらく、別の方法がありますか、そのようなタスクのサポートが組み込まれていますか?
ありがとうございます!