【发布时间】:2014-01-23 03:07:59
【问题描述】:
我有一个 WPF DataGrid 通过 dg.ItemsSource = myCollection; 绑定到 ObservableCollection
MyClass 实现了INotifyPropertyChanged。我有一个计算出来的属性,它是异步计算的。
该属性是绑定到文本颜色的 SolidColorBrush。属性值更改后,DataGrid 不会立即更新,但只要我选择属性更改的项目的行,它就会立即更新,它会显示更新后的值。
如何让 DataGrid 立即更新?我不能对 ItemsSource 使用 XAML 绑定。
绑定:
<DataGridTextColumn Foreground={Binding Path=MyBrushProperty} />
类代码:
public class MyClass : INotifyPropertyChanged
{
public SolidColorBrush MyBrushProperty {
get {
CalcMyBrush();
return _myBrushProperty;
}
set{
_myBrushProperty = value;
OnPropertyChanged("MyBrushProperty");
}
}
private void CalcMyBrush(){
//DoSomething that changes _myBrushProperty and takes some time and needs to run async and after that sets
MyBrushProperty = somevalue;
}
}
【问题讨论】:
-
在此处发布相关的 XAML 代码。
-
@RohitVats 基本上是 Foreground={Binding Path=MyColorProperty}
-
如果异步评估,请尝试在绑定中指定异步。
Foreground={Binding Path=MyColorProperty,IsAsync=True}. -
I can't use XAML binding in this case- 什么? -
@HighCore 添加了虚拟代码并解释了