コード例 #1
0
 /// <summary>
 /// Executes the NewVMCommand
 /// </summary>
 private void ExecuteNewVMCommand()
 {
     if (CurrentVM != null)
     {
         if (messageBoxService.ShowYesNo("There is an active ViewModel, loose edits?",
                                         CustomDialogIcons.Question) == CustomDialogResults.Yes)
         {
             CurrentVM = new InMemoryViewModel();
         }
         //Start out with PropertiesViewModel shown
         PropertiesViewModel propertiesViewModel =
             new PropertiesViewModel();
         propertiesViewModel.IsCloseable = false;
         CurrentVM.PropertiesVM          = propertiesViewModel;
     }
     else
     {
         CurrentVM = new InMemoryViewModel();
         //Start out with PropertiesViewModel shown
         PropertiesViewModel propertiesViewModel =
             new PropertiesViewModel();
         propertiesViewModel.IsCloseable = false;
         CurrentVM.PropertiesVM          = propertiesViewModel;
     }
 }
コード例 #2
0
        /// <summary>
        /// Creates a new InMemoryViewModel by reading the persisted XML file from disk
        /// </summary>
        private void HydrateViewModelFromXml()
        {
            //Ask the user where they want to open the file from, and open it
            try
            {
                openFileService.InitialDirectory = AppDomain.CurrentDomain.BaseDirectory;
                openFileService.FileName         = String.Empty;
                openFileService.Filter           = "Xml files (*.xml)|*.xml";
                bool?result = openFileService.ShowDialog(null);

                if (result.HasValue && result.Value)
                {
                    //open to XML
                    PesistentVM pesistentVM =
                        ViewModelPersistence.HydratePersistedViewModel(openFileService.FileName);
                    //check we got something, and recreate the full weight InMemoryViewModel from
                    //the lighter weight XML read PesistentVM
                    if (pesistentVM != null)
                    {
                        CurrentVM = new InMemoryViewModel();

                        //Start out with PropertiesViewModel shown
                        PropertiesViewModel propertiesViewModel =
                            new PropertiesViewModel();
                        propertiesViewModel.IsCloseable = false;
                        CurrentVM.PropertiesVM          = propertiesViewModel;
                        //and now read in other data
                        CurrentVM.ViewModelName        = pesistentVM.VMName;
                        CurrentVM.CurrentViewModelType = pesistentVM.VMType;
                        CurrentVM.ViewModelNamespace   = pesistentVM.VMNamespace;
                        //and add in the individual properties
                        foreach (var prop in pesistentVM.VMProperties)
                        {
                            CurrentVM.PropertiesVM.PropertyVMs.Add(new
                                                                   SinglePropertyViewModel
                            {
                                PropertyType   = prop.PropertyType,
                                PropName       = prop.PropName,
                                UseDataWrapper = prop.UseDataWrapper
                            });
                        }

                        HasContent = true;
                    }
                    else
                    {
                        messageBoxService.ShowError(String.Format("Could not open the ViewModel {0}",
                                                                  openFileService.FileName));
                    }
                }
            }
            catch (Exception ex)
            {
                messageBoxService.ShowError("An error occurred trying to Opening the ViewModel\r\n" +
                                            ex.Message);
            }
        }
コード例 #3
0
        /// <summary>
        /// Creates a new InMemoryViewModel by reading the persisted XML file from disk
        /// </summary>
        private void HydrateViewModelFromXml()
        {

            //Ask the user where they want to open the file from, and open it
            try
            {
                openFileService.InitialDirectory = AppDomain.CurrentDomain.BaseDirectory;
                openFileService.FileName = String.Empty;
                openFileService.Filter = "Xml files (*.xml)|*.xml";
                bool? result = openFileService.ShowDialog(null);

                if (result.HasValue && result.Value)
                {
                    //open to XML
                    PesistentVM pesistentVM =
                        ViewModelPersistence.HydratePersistedViewModel(openFileService.FileName);
                    //check we got something, and recreate the full weight InMemoryViewModel from
                    //the lighter weight XML read PesistentVM
                    if (pesistentVM != null)
                    {
                        CurrentVM = new InMemoryViewModel();

                        //Start out with PropertiesViewModel shown
                        PropertiesViewModel propertiesViewModel =
                            new PropertiesViewModel();
                        propertiesViewModel.IsCloseable = false;
                        CurrentVM.PropertiesVM = propertiesViewModel;
                        //and now read in other data
                        CurrentVM.ViewModelName = pesistentVM.VMName;
                        CurrentVM.CurrentViewModelType = pesistentVM.VMType;
                        CurrentVM.ViewModelNamespace = pesistentVM.VMNamespace;
                        //and add in the individual properties
                        foreach (var prop in pesistentVM.VMProperties)
                        {
                            CurrentVM.PropertiesVM.PropertyVMs.Add(new
                            SinglePropertyViewModel
                            {
                                PropertyType = prop.PropertyType,
                                PropName = prop.PropName,
                                UseDataWrapper = prop.UseDataWrapper
                            });
                        }

                        HasContent = true;
                    }
                    else
                    {
                        messageBoxService.ShowError(String.Format("Could not open the ViewModel {0}",
                        openFileService.FileName));
                    }

                    }

            }
            catch (Exception ex)
            {
                messageBoxService.ShowError("An error occurred trying to Opening the ViewModel\r\n" +
                    ex.Message);
            }
        }
コード例 #4
0
        /// <summary>
        /// Executes the NewVMCommand
        /// </summary>
        private void ExecuteNewVMCommand()
        {
            if (CurrentVM != null)
            {
                if (messageBoxService.ShowYesNo("There is an active ViewModel, loose edits?",
                    CustomDialogIcons.Question) == CustomDialogResults.Yes)
                    CurrentVM = new InMemoryViewModel();
                    //Start out with PropertiesViewModel shown
                    PropertiesViewModel propertiesViewModel =
                        new PropertiesViewModel();
                    propertiesViewModel.IsCloseable = false;
                    CurrentVM.PropertiesVM = propertiesViewModel;
            }
            else
            {
                CurrentVM = new InMemoryViewModel();
                //Start out with PropertiesViewModel shown
                PropertiesViewModel propertiesViewModel =
                    new PropertiesViewModel();
                propertiesViewModel.IsCloseable = false;
                CurrentVM.PropertiesVM = propertiesViewModel;
            }


        }