[英]How to refresh Devexpress GridControl ItemsSource(as Datatable) in MVVM(WPF)
I have a GridControl(Devexpress v13) in view(WPF). 我在view(WPF)中有一个GridControl(Devexpress v13)。 A Datatable set values in ViewModel and assigned to ItemsSource.
一个Datatable在ViewModel中设置值并分配给ItemsSource。 But ItemsSource filled only initialize.
但是ItemsSource只能填充初始化。 Later Datatable's value changes but it doesn't refresh.
之后,Datatable的值会更改,但不会刷新。 How to ItemsSource refresh?
如何对ItemsSource进行刷新?
<dxg:GridControl Name="GridControlData" DataSource="{Binding DtCriterias, Mode=TwoWay}" HorizontalAlignment="Left" VerticalAlignment="Top" AutoGenerateColumns="AddNew" Width="400" Height="100">
I hope you know what I mean. 我希望你明白我的意思。 Any help will be much appreciated.
任何帮助都感激不尽。
Thanks in advance. 提前致谢。
Edit: Property changed using: 编辑:使用以下属性更改:
public DataTable DtCriterias {
get { return _dtCriterias; }
set
{
_dtCriterias = value;
Notify(() => DtCriterias);
}
}
protected void Notify(Expression<Func<object>> expression)
{
if (_propertyChangedEvent == null) return;
Notify(GetPropertyName(expression));
}
protected void Notify(string propertyName)
{
if (_propertyChangedEvent != null)
{
_propertyChangedEvent(this, new PropertyChangedEventArgs(propertyName));
}
}
public ObservableCollection<ClientB2B> Clients
{
get
{
return _clients;
}
set
{
if (_clients == value) return;
_clients = value;
OnPropertyChanged(); // This is what you need
}
}
Implement this interface - INotifyPropertyChanged 实现此接口-INotifyPropertyChanged
protected void OnPropertyChanged(PropertyChangedEventArgs e)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
handler(this, e);
}
protected void OnPropertyChanged(string propertyName)
{
OnPropertyChanged(new PropertyChangedEventArgs(propertyName));
}
public event PropertyChangedEventHandler PropertyChanged;
I found reason of problem. 我发现了问题的原因。 I am using encapsulation and I was set private value(_dtCriterias).
我正在使用封装,并且设置了私有值(_dtCriterias)。 Therefore Property Changed Event wasn't work.
因此,属性更改事件不起作用。
Definitions: 定义:
private DataTable _dtCriterias;
public DataTable DtCriterias {
get { return _dtCriterias; }
set
{
_dtCriterias = value;
Notify(() => DtCriterias);
}
}
When I have problem datatable set: 当我设置了问题数据表时:
_dtCriterias = GetValue().DefaultView.ToTable("FooTable");
Solution: 解:
DtCriterias = GetValue().DefaultView.ToTable("FooTable");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.