开发者

Dynamically populating UI with C#/WPF

I have a DLL that I can use to pull the following information about individuals from a database:

-first name

-last name

-age

-name of task

-progress of that task (percentage)

I'd like to display that information with WPF (or other 开发者_开发百科technology if that makes it much easier) in my Windows Application. Every 5 seconds, the application will use the DLL to get the new info and update the display. I want to display first name, last name, age etc in its own column, and the number of individuals will change over time.

I think I can figure out how to use the DLL in C#, but I'm having problems finding info about dynamically adding/removing controls from a window in WPF.

Any pointers are appreciated!


You probably want to use a design pattern such as MVVM(Model-View-ViewModel) to abstract DLL (which knows nothing about WPF) and your main application.

This MSDN article goes in to detail about how to use it to work with collections of data and use databinding to automatically update.


You could also look at PRISM, aka CAG, which can also be used for Silverlight 3. There is a printable set of docs here. It looks complicated but you can just use the bits you want.

Basically, whichever way you do MVVM, you'll probably end up with some kind of Grid in your View which is databound to some kind of ObservableCollection in your ViewModel which gets its data from the Model, such that any changes to the ObsColln just appear in the UI without you doing anything else. Nice.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜