更新时间:2022-04-29 02:28:51
InitializeComponent()
将实例化标记,包括绑定.此时, DTUsers
仍然为 null
,因此什么也不显示.然后,您更改 DTUsers
,但是绑定(因此网格)无法知道您已完成操作-因此它不会执行任何操作.
InitializeComponent()
will instantiate your markup, including the binding. At that point DTUsers
is still null
, so nothing is displayed. Then, you change DTUsers
, but there's no way for the binding (and therefore the grid) to know that you did it - and so it does not do anything.
您应该将 DTUsers
设置为依赖项属性,或者在您的类上实现 INotifyPropertyChanged
,并在更改的值后引发 PropertyChanged
事件财产.
You should either make DTUsers
a dependency property, or implement INotifyPropertyChanged
on your class, and raise PropertyChanged
event after you change the value of the property.