WPF,用户控制,窗口WPF应用程序

WPF,用户控制,窗口WPF应用程序

问题描述:

大家好,

帮助我,我坚持使用我的代码。

我有一些疑问Plz验证我..

1.我如何刷新我的用户控件?它的UpdateLayout()足够吗?



它的(UC)现在作为网格本身的子项添加到主窗口。但需要使用新值刷新此UC,但数据是从单独的窗口提供的。那个窗口包含一个listview,关于这个选择更改需要刷新这个用户控件..



请帮我吧非常紧急..



提前感谢。

Hi all,
help me, Im stuck with my code.
I have some doubt Plz Verify me..
1. How i can refresh my usercontrol? is it UpdateLayout() enough?

its(UC)now added to mainwindow as child of a grid itself. but need to refresh this UC with new value, but data is supplied from a separate window. that window contain a listview, on this selection change need to refresh this usercontrol..

please help me its very urgent..

thanks in advance .

Hello

从模型(代码)中的属性获取自动更新视图(gui),你应该确保一些东西。



1)你应该使用视图中的Bindings到模型

2)模型中用于Bindings的属性也应该在类中具有DependencyProperty

3)模型类本身应该实现INotifyPropertyChanged接口,以便属性可以通知更改。

4)列表应该是ObservableCollection<>而不是List<>因为它继承了ICollectionChanged接口。



这样,你再也不会担心UpdateLayout()或DoEvents()或类似的东西。



如果你想在模型中运行一个长时间运行的方法时更新值live,你应该在一个Thread中运行该方法,比如BackgroundWorker。



希望它有所帮助!
Hello
To get automatic updates from properties in the model (code) to the view (gui), there are some things you should ensure.

1) You should use Bindings from the view to the model
2) The properties in the model that are used in Bindings should also have a DependencyProperty in the class
3) The model class itself should implement the INotifyPropertyChanged interface so the properties can notify changes.
4) Lists should be ObservableCollection<> instead of List<> because it inherits the ICollectionChanged interface.

This way, you will never again worry about UpdateLayout() or DoEvents() or anything like that.

If you like to update the values "live" while running a long-running method in the model, you should run that method in a Thread, like i.e. a BackgroundWorker.

Hope it helps!