简体   繁体   中英

Push on a ComboBox using WPF MVVM

I have a combobox in a WPF Window, it is filled with usernames from database,

When a new user is created in database, i want the UserName to be pushed to the ComboBox, ie, added to the existing.

Similary when a User is deleted, it should be Poped from the ComboBox .

How can i do this. Currently, i am using WPF MVVM with Caliburn Micro .

I bind the ItemsSource to an ObservableCollection for that. Works when you add or delete items from the collection.

If you're using MVVM then you should have some collection that is bound to ComboBox.ItemsSource property. If any changes to collection were made - invoke FireProeprtyChanged("UsersCollection") . UI should reflect on this and update ComboBox .

Update:
If you want to provide some kind of push notifications - you have to create HTTP Polling Duplex WCF Service. Nice example of its implementation by Dan Wahlin: Syncing Data with a Server using Silverlight and HTTP Polling Duplex

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM