コード例 #1
0
ファイル: WindowManager.cs プロジェクト: hu13779472390/MvvmFx
            public WindowConductor(object model, Window view)
            {
                this.model = model;
                this.view  = view;

                var activatable = model as IActivate;

                if (activatable != null)
                {
                    activatable.Activate();
                }

                var deactivatable = model as IDeactivate;

                if (deactivatable != null)
                {
                    view.Closed += Closed;
                    deactivatable.Deactivated += Deactivated;
                }

                var guard = model as IGuardClose;

                if (guard != null)
                {
                    view.Closing += Closing;
                }
            }
コード例 #2
0
ファイル: Logon.cs プロジェクト: wtnj/sigaweb
 /// <summary>
 ///     Unico acesso externo, pois todo o trafego de informaçoes eh monitorado
 /// pelo conjunto de userControls, SigaControle com o objeto SigaSession.
 /// </summary>
 /// <param name="username">usuario de sistema</param>
 /// <param name="password">senha do usuario setado</param>
 /// <param name="inForm"  >webguiForm onde o Main(menu e janela principal) será carregado, caso seja autenticado</param>
 public Logon(string username, string password, List <string> nomes, Gizmox.WebGUI.Forms.Form inForm)
 {
     try
     {
         if (nomes.Count > 0)
         {
             if (username.Equals("") || password.Equals(""))
             {
                 MessageBox.Show("Favor preencher Login e/ou Senha !");
             }
             else
             {
                 sigaSession.Logon(username, password);
                 //new EmpresaDao().Load(sigaSession.EMPRESAS, nomes);
                 inForm.Controls.Clear();
                 FormatScreen.AddControl(inForm, new MainMenu(), true);
             }
         }
         else
         {
             MessageBox.Show("Selecione alguma empresa !");
         }
     }
     catch (Exception e)
     {
         MessageBox.Show(e.Message);
     }
 }
コード例 #3
0
ファイル: WindowManager.cs プロジェクト: hu13779472390/MvvmFx
        /// <summary>
        /// Creates a Form.
        /// </summary>
        /// <param name="rootModel">The root view model.</param>
        /// <param name="isDialog">if set to <c>true</c> the Form is a dialog.</param>
        /// <param name="context">The view context.</param>
        /// <param name="settings">The optional popup settings.</param>
        /// <param name="rootForm">The root form.</param>
        /// <returns>The created Form.</returns>
        /// <remarks>
        /// The calling method only passes the root form parameter in ShowMainWindow, when the main form already exists.
        /// This is necessary for Visual WebGUI (or Windows if the Bootstrapper is invoked after the main form creation).
        /// </remarks>
        protected virtual Window CreateWindow(object rootModel, bool isDialog, object context,
                                              IDictionary <string, object> settings, Window rootForm = null)
        {
            Window view;

            if (rootForm != null)
            {
                view = rootForm;
            }
            else
            {
                view = EnsureWindow(rootModel, ViewLocator.LocateForModel(rootModel, null, null), isDialog);
            }

            ViewModelBinder.Bind(rootModel, view, null);

            var haveDisplayName = rootModel as IHaveDisplayName;

            if (haveDisplayName != null && !ConventionManager.HasBinding(view, "Text"))
            {
                view.DataBindings.Add(new Binding("Text", rootModel, "DisplayName", true,
                                                  DataSourceUpdateMode.OnPropertyChanged));
            }

            ApplySettings(view, settings);

            new WindowConductor(rootModel, view);

            return(view);
        }
コード例 #4
0
ファイル: WindowManager.cs プロジェクト: hu13779472390/MvvmFx
        /// <summary>
        /// Shows a Form for the specified model.
        /// </summary>
        /// <param name="rootModel">The root model.</param>
        /// <param name="context">The context.</param>
        /// <param name="settings">The optional Form settings.</param>
        public virtual void ShowWindow(object rootModel, object context      = null,
                                       IDictionary <string, object> settings = null)
        {
            NavigationWindow navWindow = null;

            if (ApplicationContext.MainWindow != null)
            {
                navWindow = ApplicationContext.MainWindow;
            }

            if (navWindow != null)
            {
                //var window = CreatePage(rootModel, context, settings);
                //navWindow.Navigate(window);
            }
            else
            {
                var window = CreateWindow(rootModel, true, context, settings);

                if (FormStartPosition.CenterParent == window.StartPosition && null != window.Owner)
                {
                    window.StartPosition = FormStartPosition.Manual;
                    window.Location      =
                        new Point(
                            window.Owner.Location.X + (window.Owner.Width - window.Width) / 2,
                            window.Owner.Location.Y + (window.Owner.Height - window.Height) / 2);
                }

                Execute.OnUIThread(() => { window.Show(); });
            }
        }
コード例 #5
0
ファイル: WindowManager.cs プロジェクト: hu13779472390/MvvmFx
        /// <summary>
        /// Infers the owner of the Form.
        /// </summary>
        /// <param name="window">The Form to whose owner needs to be determined.</param>
        /// <returns>The Form's owner.</returns>
        protected virtual Window InferOwnerOf(Window window)
        {
            if (ApplicationContext.MainWindow == null)
            {
                return(null);
            }

            var active = Application.OpenForms.Cast <Window>().FirstOrDefault();

            active = active ?? ApplicationContext.MainWindow;
            return(active == window ? null : active);
        }
コード例 #6
0
ファイル: WindowManager.cs プロジェクト: hu13779472390/MvvmFx
        /// <summary>
        /// Makes sure the view is a Form or is wrapped by one.
        /// </summary>
        /// <param name="model">The view model.</param>
        /// <param name="view">The view.</param>
        /// <param name="isDialog">if set to <c>true</c>, the Form is being shown as a dialog.</param>
        /// <returns>The original Form or a new Form embedding the "view" control.</returns>
        protected virtual Window EnsureWindow(object model, object view, bool isDialog)
        {
            var window = view as Window;

            if (window == null)
            {
                window = new Window();

                var contentControl = new ContentContainer()
                {
                    Dock     = DockStyle.Fill,
                    Location = new Point(0, 0),
                    TabIndex = 0,
                    Content  = model
                               // when setting the Content property, the setter will locate and load the view
                };

                //window.SetValue(View.IsGeneratedProperty, true);
                window.Controls.Add(contentControl);

#if WEBGUI
                var owner = ApplicationContext.WebGUIActiveForm;
#else
                var owner = Window.ActiveForm;
#endif
                if (null != owner && window != owner)
                {
                    window.StartPosition = FormStartPosition.CenterParent;
                    window.Owner         = owner;
                }
                else
                {
                    window.StartPosition = FormStartPosition.CenterScreen;
                }
            }
            else
            {
                var owner = InferOwnerOf(window);
                if (owner != null && isDialog)
                {
                    window.Owner = owner;
                }
                else if (owner == null)
                {
                    window.StartPosition = FormStartPosition.CenterScreen;
                }
            }

            return(window);
        }
コード例 #7
0
ファイル: WindowManager.cs プロジェクト: hu13779472390/MvvmFx
        /*/// <summary>
         * /// Shows a popup at the current mouse position.
         * /// </summary>
         * /// <param name="rootModel">The root model.</param>
         * /// <param name="context">The view context.</param>
         * /// <param name="settings">The optional popup settings.</param>
         * public virtual void ShowPopup(object rootModel, object context = null,
         *  IDictionary<string, object> settings = null)
         * {
         *  var popup = CreatePopup(rootModel, settings);
         *  var view = ViewLocator.LocateForModel(rootModel, popup, context);
         *
         *  popup.Child = view;
         *  //popup.SetValue(View.IsGeneratedProperty, true);
         *
         *  ViewModelBinder.Bind(rootModel, popup, null);
         *  Action.SetTargetWithoutContext(view, rootModel);
         *
         *  var activatable = rootModel as IActivate;
         *  if (activatable != null)
         *  {
         *      activatable.Activate();
         *  }
         *
         *  var deactivator = rootModel as IDeactivate;
         *  if (deactivator != null)
         *  {
         *      popup.Closed += delegate { deactivator.Deactivate(true); };
         *  }
         *
         *  popup.IsOpen = true;
         *  popup.CaptureMouse();
         * }
         *
         * /// <summary>
         * /// Creates a popup for hosting a popup window.
         * /// </summary>
         * /// <param name="rootModel">The model.</param>
         * /// <param name="settings">The optional popup settings.</param>
         * /// <returns>The popup.</returns>
         * protected virtual Popup CreatePopup(object rootModel, IDictionary<string, object> settings)
         * {
         *  var popup = new Popup();
         *
         *  if (ApplySettings(popup, settings))
         *  {
         *      if (!settings.ContainsKey("PlacementTarget") && !settings.ContainsKey("Placement"))
         *          popup.Placement = PlacementMode.MousePoint;
         *      if (!settings.ContainsKey("AllowsTransparency"))
         *          popup.AllowsTransparency = true;
         *  }
         *  else
         *  {
         *      popup.AllowsTransparency = true;
         *      popup.Placement = PlacementMode.MousePoint;
         *  }
         *
         *  return popup;
         * }*/

        /// <summary>
        /// For the specified model, shows a Form that is supposed to be the main application form.
        /// </summary>
        /// <param name="rootModel">The root model.</param>
        /// <param name="context">The context.</param>
        /// <param name="settings">The optional Form settings.</param>
        public virtual void ShowMainWindow(object rootModel, object context      = null,
                                           IDictionary <string, object> settings = null)
        {
            if (ApplicationContext.StartupForm != null)
            {
                Window root = CreateWindow(rootModel, true, context, settings, ApplicationContext.StartupForm);
                new ApplicationContext(root);
            }
#if WINFORMS
            else
            {
                Window root = CreateWindow(rootModel, true, context, settings);
                var    applicationContext = new ApplicationContext(root);
                Execute.OnUIThread(() =>
                {
                    //applicationContext.MainForm.ShowDialog();
                    Application.Run(applicationContext);
                });
            }
#endif
        }
コード例 #8
0
            public WindowConductor(object model, Window view)
            {
                this.model = model;
                this.view = view;

                var activatable = model as IActivate;
                if (activatable != null)
                {
                    activatable.Activate();
                }

                var deactivatable = model as IDeactivate;
                if (deactivatable != null)
                {
                    view.Closed += Closed;
                    deactivatable.Deactivated += Deactivated;
                }

                var guard = model as IGuardClose;
                if (guard != null)
                {
                    view.Closing += Closing;
                }
            }
コード例 #9
0
        /// <summary>
        /// Infers the owner of the Form.
        /// </summary>
        /// <param name="window">The Form to whose owner needs to be determined.</param>
        /// <returns>The Form's owner.</returns>
        protected virtual Window InferOwnerOf(Window window)
        {
            if (ApplicationContext.MainWindow == null)
            {
                return null;
            }

            var active = Application.OpenForms.Cast<Window>().FirstOrDefault();
            active = active ?? ApplicationContext.MainWindow;
            return active == window ? null : active;
        }
コード例 #10
0
        /// <summary>
        /// Makes sure the view is a Form or is wrapped by one.
        /// </summary>
        /// <param name="model">The view model.</param>
        /// <param name="view">The view.</param>
        /// <param name="isDialog">if set to <c>true</c>, the Form is being shown as a dialog.</param>
        /// <returns>The original Form or a new Form embedding the "view" control.</returns>
        protected virtual Window EnsureWindow(object model, object view, bool isDialog)
        {
            var window = view as Window;

            if (window == null)
            {
                window = new Window();

                var contentControl = new ContentContainer()
                {
                    Dock = DockStyle.Fill,
                    Location = new Point(0, 0),
                    TabIndex = 0,
                    Content = model
                    // when setting the Content property, the setter will locate and load the view
                };

                //window.SetValue(View.IsGeneratedProperty, true);
                window.Controls.Add(contentControl);

#if WEBGUI
                var owner = ApplicationContext.WebGUIActiveForm;
#else
                var owner = Window.ActiveForm;
#endif
                if (null != owner && window != owner)
                {
                    window.StartPosition = FormStartPosition.CenterParent;
                    window.Owner = owner;
                }
                else
                {
                    window.StartPosition = FormStartPosition.CenterScreen;
                }
            }
            else
            {
                var owner = InferOwnerOf(window);
                if (owner != null && isDialog)
                {
                    window.Owner = owner;
                }
                else if (owner == null)
                {
                    window.StartPosition = FormStartPosition.CenterScreen;
                }
            }

            return window;
        }
コード例 #11
0
        /// <summary>
        /// Creates a Form.
        /// </summary>
        /// <param name="rootModel">The root view model.</param>
        /// <param name="isDialog">if set to <c>true</c> the Form is a dialog.</param>
        /// <param name="context">The view context.</param>
        /// <param name="settings">The optional popup settings.</param>
        /// <param name="rootForm">The root form.</param>
        /// <returns>The created Form.</returns>
        /// <remarks>
        /// The calling method only passes the root form parameter in ShowMainWindow, when the main form already exists.
        /// This is necessary for Visual WebGUI (or Windows if the Bootstrapper is invoked after the main form creation).
        /// </remarks>
        protected virtual Window CreateWindow(object rootModel, bool isDialog, object context,
            IDictionary<string, object> settings, Window rootForm = null)
        {
            Window view;
            if (rootForm != null)
                view = rootForm;
            else
                view = EnsureWindow(rootModel, ViewLocator.LocateForModel(rootModel, null, null), isDialog);

            ViewModelBinder.Bind(rootModel, view, null);

            var haveDisplayName = rootModel as IHaveDisplayName;
            if (haveDisplayName != null && !ConventionManager.HasBinding(view, "Text"))
            {
                view.DataBindings.Add(new Binding("Text", rootModel, "DisplayName", true,
                    DataSourceUpdateMode.OnPropertyChanged));
            }

            ApplySettings(view, settings);

            new WindowConductor(rootModel, view);

            return view;
        }