示例#1
0
        /// <summary>
        /// Command executed when the Open With Context Menu is clicked.
        /// </summary>
        protected virtual async Task OpenViewAsync()
        {
            string message;

			try
			{
				if (string.IsNullOrEmpty(AssemblyName))
				{
					message = await GetText("EmptyAssemblyName", BaseConstants.SpecifySmallerTextBoxTextDefaultValue,
						ClassName);

					BaseViewModel.ShowInformationMessage(message);
					return;
				}

				if (string.IsNullOrEmpty(ViewName))
				{
					message = await GetText("EmptyViewName", BaseConstants.EmptyViewNameDefaultValue,
						ClassName);

					BaseViewModel.ShowInformationMessage(message);
					return;
				}

				message = await GetText("LoadingBusinessObject", BaseConstants.LoadingBusinessObjectDefaultValue, ClassName);

				BaseViewModel.SetViewIsBusy(message);

				dynamic view = ViewUtil.IsWindowOpen(ViewName);

				if (view != null)
				{
					view.DataContext.LoadModel(SelectedBusinessObject);

					if (view.WindowState == WindowState.Minimized)
					{
						view.WindowState = WindowState.Normal;
					}

					view.Focus();
					return;
				}

				view = await BaseViewModel.CreateInstance(ViewName, AssemblyName);
				//view.Width = BaseViewModel.ConstWidthView;
				//view.Height = BaseViewModel.ConstHeightView;

				view.Show();

				//The LoadModel Method is implemented in the BaseCRUDViewModel class.
				view.DataContext.LoadModel(SelectedBusinessObject);
			}
			catch(Exception)
			{
				throw;
			}
			finally
			{
				BaseViewModel.ViewIsBusy = false;
			}
        }