小编Gun*_*ter的帖子

视图模型中的计时器

我在外部程序集中有服务类,我在MEF的视图模型类中注入此类.我需要从视图模型每3-4秒调用一次服务方法.

我从服务新数据获得字典.此词典在视图中绑定到列表框.我需要在视图中使用此数据列表框进行刷新.

在我的解决方案中,我使用DispatcherTimer,但我在calibur.micto中也是MVVM和WPF的绝对优势.在我的案例中,我不知道什么是合适的解决方案.所以,如果有人提前,我将感激不尽.

我的解决方案在这里:

[Export("MainScreen", typeof(IMainViewModel))]
    public class MainViewModel : Screen, IMainViewModel
    {

        [Import]
        private Service _service;//import with MEF from external assembly
        [Import]
        private Connection _conn;//import with MEF from external assembly

        //this dictionary is bind to the listbox in view
        private MyObservableDictionary<string, User> _users = null;

        //temp dictionry
        private MyObservableDictionary<string, User> _freshUsers = null;

        private int _selectedUserIndex;

        private DispatcherTimer _dispatcherTimer;


        public Account Account{ get; set;}

        public int SelectedUsersIndex
        {
            get { return _selectedUserIndex; }
            set
            {
                _selectedUserIndex = value;
                NotifyOfPropertyChange("SelectedUsersIndex"); …
Run Code Online (Sandbox Code Playgroud)

c# timer viewmodel caliburn.micro

5
推荐指数
1
解决办法
4973
查看次数

标签 统计

c# ×1

caliburn.micro ×1

timer ×1

viewmodel ×1