Example #1
0
        public override void OpenFunction(string AssemblyName)
        {
            _ExistFunction = _Functions.FirstOrDefault(a => a.FunctionName.ToLowerInvariant().Equals(AssemblyName.ToLowerInvariant()));
            if (_ExistFunction == null)
            {
                return;
            }

            _ExistVM = this.Workspaces.FirstOrDefault(vm => vm.GetType().Name.ToLowerInvariant().Equals(_ExistFunction.EntryTypeName.ToLowerInvariant()));
            if (_ExistVM != null)
            {
                SetActiveWorkspace(_ExistVM);
                return;
            }

            if (!_FunctionTypeDictionary.TryGetValue(_ExistFunction.EntryTypeName, out _ExistType))
            {
                try
                {
                    _TemObj = Application.LoadComponent(new Uri(_ExistFunction.AssemblyUri, UriKind.Relative));
                    Application.Current.Resources.MergedDictionaries.Add(_TemObj as ResourceDictionary);
                }
                catch
                {
                    return;
                }
                if (_TemObj != null && _TemObj is ResourceDictionary)
                {
                    _TemAssemblies = AppDomain.CurrentDomain.GetAssemblies();
                    if (_TemAssemblies != null)
                    {
                        _ExistAssembly = _TemAssemblies.FirstOrDefault(a => a.GetName().Name.ToLowerInvariant() == _ExistFunction.AssemblyName.ToLowerInvariant());
                        if (_ExistAssembly != null)
                        {
                            _ExistType = _ExistAssembly.GetTypes().FirstOrDefault(a => a.Name.ToLowerInvariant().Equals(_ExistFunction.EntryTypeName.ToLowerInvariant()));
                        }
                    }
                }
            }

            if (_ExistType != null)
            {
                _TemObj = Activator.CreateInstance(_ExistType);
                if (_TemObj != null && _TemObj is ViewModelBase)
                {
                    _TempVM = (_TemObj as ViewModelBase);
                    _TempVM.Title = _ExistFunction.FunctionTitle;
                    _TempVM.InitializeSpecific();
                    if (!_FunctionTypeDictionary.ContainsKey(_ExistFunction.EntryTypeName))
                    {
                        _FunctionTypeDictionary.Add(_ExistFunction.EntryTypeName, _ExistType);
                    }
                    Workspaces.Add(_TempVM);
                    SetActiveWorkspace(_TempVM);
                }
            }
        }
Example #2
0
        private void SetActiveWorkspace(ViewModelBase workspace)
        {
            Debug.Assert(this.Workspaces.Contains(workspace));

            ICollectionView collectionView = CollectionViewSource.GetDefaultView(this.Workspaces);
            if (collectionView != null)
                collectionView.MoveCurrentTo(workspace);
        }
Example #3
0
        public void ShowDialog(ViewModelBase dialogModel)
        {
            var v = new Window();
            var vm = dialogModel;
            Binding tagBinding = null;
            object windowTagValue=null;
            v.DataContext = vm;
            vm.HostWindow =v;
            if (!string.IsNullOrWhiteSpace(vm._DirtyDetectBindingPath) && vm._EditingData!=null)
            {
                tagBinding = new Binding(vm._DirtyDetectBindingPath);
                tagBinding.UpdateSourceTrigger=UpdateSourceTrigger.PropertyChanged;
                BindingOperations.SetBinding(v, Window.TagProperty, tagBinding);

                v.Closing += (o, e) =>
                {
                    if (vm._CloseTipFlag)
                    {
                        windowTagValue = v.GetValue(Window.TagProperty);
                        if (windowTagValue != null && windowTagValue is bool && (bool)windowTagValue)
                        {
                            if (MessageBox.Show("所编辑的数据将被取消,是否继续?", "操作提示", MessageBoxButton.YesNo, MessageBoxImage.Question) != MessageBoxResult.Yes)
                            {
                                e.Cancel = true;
                            }
                            else
                            {
                                vm._EditingData.StopDirtyDetect();
                                vm._IsEditingDataEnableValidation = false;
                                vm._EditingData.IsEnableValidation = false;
                            }
                        }
                    }
                    else
                    {
                        vm._EditingData.StopDirtyDetect();
                        vm._IsEditingDataEnableValidation = false;
                        vm._EditingData.IsEnableValidation = false;
                    }

                };
            }
            vm.ParentModel = this;
            vm.MainWindow = this.MainWindow;
            BindingOperations.SetBinding(v,Window.ContentProperty,new Binding());
            BindingOperations.SetBinding(v,Window.TitleProperty,new Binding("Title"));
            v.SizeToContent=SizeToContent.WidthAndHeight;
            v.ResizeMode=ResizeMode.NoResize;
            v.Icon=this.MainWindow.Icon;
            v.Owner=this.HostWindow;
            v.WindowStartupLocation=WindowStartupLocation.CenterOwner;
            v.Loaded += (o, e) =>
            {
                if (vm._EditingData != null)
                {
                    vm._EditingData.IsEnableValidation = vm._IsEditingDataEnableValidation;
                }
            };
            v.ShowDialog();
        }