Пример #1
0
 public NotificationBarViewModel(NotificationSourceViewModel[] sources)
 {
     _sources = new DispatcherNotifiedObservableCollection <NotificationSourceViewModel>();
     foreach (var source in sources)
     {
         AddSource(source);
     }
     setupCommand();
 }
        public NotificationItemViewModel(NotificationItemModel embeddedModel)
        {
            _embeddedModel = embeddedModel;
            _commands      = new DispatcherNotifiedObservableCollection <CommandViewModel>();

            setupDoWorkCommand();
            setupBackgroundWorker();

            bgWorker_loadCommands.RunBackgroundTask();
            _embeddedModel.OnCommandsChanged += (o, e) => { bgWorker_loadCommands.RunBackgroundTask(); };
            _embeddedModel.OnRemoveRequested += (o, e) => { if (ParentModel != null)
                                                            {
                                                                ParentModel.RemovePending();
                                                            }
            };
            _embeddedModel.PropertyChanged += (o, e) =>
            {
                switch (e.PropertyName)
                {
                case "NotificationMode":
                    if (ProgressBrushDic.ContainsKey(_embeddedModel.NotificationMode))
                    {
                        ProgressForeground = ProgressBrushDic[_embeddedModel.NotificationMode];
                    }
                    if (_embeddedModel.NotificationMode == NotificationMode.Error &&
                        PercentCompleted < 33)
                    {
                        PercentCompleted = 33;
                    }
                    break;

                case "PercentCompleted":
                    if (_embeddedModel.NotificationMode != NotificationMode.Error)
                    {
                        PercentCompleted = _embeddedModel.PercentCompleted;
                    }
                    break;
                }
            };
        }
        public DirectoryTreeItemViewModel LookupChild(DirectoryInfoEx directory, Func<bool> cancelCheck)
        {
            if (cancelCheck != null && cancelCheck())
                return null;

            if (Parent != null)
                Parent.IsExpanded = true;
            if (directory == null)
                return null;

            if (!IsLoaded)
            {
                IsLoading = true;
                SubDirectories = getDirectories();
                HasSubDirectories = SubDirectories.Count > 0;
                IsLoading = false;
            }

            foreach (DirectoryTreeItemViewModel subDirModel in SubDirectories)
            {
                if (!subDirModel.Equals(dummyNode))
                {
                    DirectoryInfoEx subDir = subDirModel.EmbeddedDirectoryModel.EmbeddedDirectoryEntry;
                    if (directory.Equals(subDir))
                        return subDirModel;
                    else if (IOTools.HasParent(directory, subDir))
                        return subDirModel.LookupChild(directory, cancelCheck);
                }
            }
            return null;
        }