Example #1
0
        public override void ShowPopup(object rootModel, object context      = null,
                                       IDictionary <string, object> settings = null)
        {
            var popup = CreatePopup(rootModel, settings);
            var view  = ViewLocator.LocateForModel(rootModel, popup, context);

            SetupRxPopup(rootModel, view, popup);

            popup.Child = view;
            popup.SetValue(View.IsGeneratedProperty, true);

            SetupCaliburn(rootModel, popup, view);

            popup.IsOpen = true;
            popup.CaptureMouse();
        }
Example #2
0
        static void OnContextChanged(DependencyObject targetLocation, DependencyPropertyChangedEventArgs e)
        {
            if (e.OldValue == e.NewValue)
            {
                return;
            }

            var model = GetModel(targetLocation);

            if (model == null)
            {
                return;
            }

            var view = ViewLocator.LocateForModel(model, targetLocation, e.NewValue);

            SetContentProperty(targetLocation, view);
            ViewModelBinder.Bind(model, view, e.NewValue);
        }
        /// <summary>
        /// Locates the view model, locates the associate view, binds them and shows it as the root view.
        /// </summary>
        /// <param name="viewModelType">The view model type.</param>
        protected void DisplayRootViewFor(Type viewModelType)
        {
            Initialise();

            var viewModel = IoC.GetInstance(viewModelType, null);
            var view      = ViewLocator.LocateForModel(viewModel, null, null);

            ViewModelBinder.Bind(viewModel, view, null);

            var activator = viewModel as IActivate;

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

            Window.Current.Content = view;
            Window.Current.Activate();
        }
        /// <summary>
        /// Locates the view model, locates the associate view, binds them and shows it as the root view.
        /// </summary>
        /// <param name="viewModelType">The view model type.</param>
        protected async Task DisplayRootViewForAsync(Type viewModelType)
        {
            var viewModel = IoC.GetInstance(viewModelType, null);
            var view      = ViewLocator.LocateForModel(viewModel, null, null);

            if (!(view is Page page))
            {
                throw new NotSupportedException(String.Format("{0} does not inherit from {1}.", view.GetType(), typeof(Page)));
            }

            ViewModelBinder.Bind(viewModel, view, null);

            if (viewModel is IActivate activator)
            {
                await activator.ActivateAsync();
            }

            MainPage = page;
        }
Example #5
0
        static void OnModelChanged(DependencyObject targetLocation, DependencyPropertyChangedEventArgs args)
        {
            if (args.OldValue == args.NewValue)
            {
                return;
            }

            if (args.NewValue != null)
            {
                var context = GetContext(targetLocation);
                var view    = ViewLocator.LocateForModel(args.NewValue, targetLocation, context);

                SetContentProperty(targetLocation, view);
                ViewModelBinder.Bind(args.NewValue, view, context);
            }
            else
            {
                SetContentProperty(targetLocation, args.NewValue);
            }
        }
        /// <summary>
        ///     Locates the view model, locates the associate view, binds them and shows it as the root view.
        /// </summary>
        /// <param name="viewModelType">The view model type.</param>
        protected void DisplayRootViewFor(Type viewModelType)
        {
            var rootElement    = NoesisView.Content;
            var contentControl = (ContentControl)rootElement.FindName(RootContentControlName);

            object viewModel = IoC.GetInstance(viewModelType, null);

            UIElement view = ViewLocator.LocateForModel(viewModel, null, null);

            ViewModelBinder.Bind(viewModel, view, null);

            var activator = viewModel as IActivate;

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

            contentControl.Content = view;
        }
Example #7
0
        /// <summary>
        /// Creates a window.
        /// </summary>
        /// <param name="rootModel">The view model.</param>
        /// <param name="isDialog">Whethor or not the window is being shown as a dialog.</param>
        /// <param name="context">The view context.</param>
        /// <returns>The window.</returns>
        protected virtual Window CreateWindow(object rootModel, bool isDialog, object context)
        {
            var view = EnsureWindow(rootModel, ViewLocator.LocateForModel(rootModel, null, context), isDialog);

            ViewModelBinder.Bind(rootModel, view, context);

            var haveDisplayName = rootModel as IHaveDisplayName;

            if (haveDisplayName != null && !ConventionManager.HasBinding(view, Window.TitleProperty))
            {
                var binding = new Binding("DisplayName")
                {
                    Mode = BindingMode.TwoWay
                };
                view.SetBinding(Window.TitleProperty, binding);
            }

            new WindowConductor(rootModel, view);

            return(view);
        }
Example #8
0
        /// <summary>
        /// Shows a modal dialog for the specified model.
        /// </summary>
        /// <param name="rootModel">The root model.</param>
        /// <param name="context">The context.</param>
        public virtual void ShowDialog(object rootModel, object context = null)
        {
            var view = EnsureWindow(rootModel, ViewLocator.LocateForModel(rootModel, null, context));

            ViewModelBinder.Bind(rootModel, view, context);

            var haveDisplayName = rootModel as IHaveDisplayName;

            if (haveDisplayName != null && !ConventionManager.HasBinding(view, ChildWindow.TitleProperty))
            {
                var binding = new Binding("DisplayName")
                {
                    Mode = BindingMode.TwoWay
                };
                view.SetBinding(ChildWindow.TitleProperty, binding);
            }

            new WindowConductor(rootModel, view);

            view.Show();
        }
Example #9
0
        private RadWindow PrepareRadWindow(object rootModel, object context, IDictionary <string, object> settings)
        {
            var view = EnsureWindow(rootModel, ViewLocator.LocateForModel(rootModel, null, context));

            ViewModelBinder.Bind(rootModel, view, context);

            var haveDisplayName = rootModel as IHaveDisplayName;

            if (haveDisplayName != null && !ConventionManager.HasBinding(view, RadWindow.HeaderProperty))
            {
                var binding = new Binding("DisplayName")
                {
                    Mode = BindingMode.TwoWay
                };
                view.SetBinding(RadWindow.HeaderProperty, binding);
            }

            new RadWindowConductor(rootModel, view);

            ApplySettings(view, settings);
            return(view);
        }
Example #10
0
        /// <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 async Task ShowPopupAsync(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);

            if (rootModel is IActivate activator)
            {
                await activator.ActivateAsync();
            }

            if (rootModel is IDeactivate deactivator)
            {
                popup.Closed += async(s, e) => await deactivator.DeactivateAsync(true);
            }

            popup.IsOpen = true;
            popup.CaptureMouse();
        }
Example #11
0
        /// <summary>
        /// Shows a settings flyout panel for the specified model.
        /// </summary>
        /// <param name="viewModel">The settings view model.</param>
        /// <param name="commandLabel">The settings command label.</param>
        /// <param name="viewSettings">The optional dialog settings.</param>
        /// <param name="independent">Show settings independent from <seealso cref="Windows.UI.ApplicationSettings.SettingsPane"/>.</param>
        public async void ShowSettingsFlyout(object viewModel, string commandLabel,
                                             IDictionary <string, object> viewSettings = null, bool independent = false)
        {
            var view = ViewLocator.LocateForModel(viewModel, null, null);

            ViewModelBinder.Bind(viewModel, view, null);

            viewSettings = viewSettings ?? new Dictionary <string, object>();

            var settingsFlyout = new SettingsFlyout
            {
                Title   = commandLabel,
                Content = view,
                HorizontalContentAlignment = HorizontalAlignment.Stretch
            };

            // extract the header color/logo from the appmanifest.xml
            var visualElements = await AppManifestHelper.GetManifestVisualElementsAsync();

            // enable the overriding of these, but default to manifest
            var headerBackground = viewSettings.ContainsKey("headerbackground")
                ? (SolidColorBrush)viewSettings["headerbackground"]
                : new SolidColorBrush(visualElements.BackgroundColor);

            var smallLogoUri = viewSettings.ContainsKey("smalllogouri")
                ? (Uri)viewSettings["smalllogouri"]
                : visualElements.SmallLogoUri;

            var smallLogo = new BitmapImage(smallLogoUri);

            // use real property names for ApplySettings
            if (!viewSettings.ContainsKey("HeaderBackground"))
            {
                viewSettings["HeaderBackground"] = headerBackground;
            }

            if (!viewSettings.ContainsKey("IconSource"))
            {
                viewSettings["IconSource"] = smallLogo;
            }

            ApplySettings(settingsFlyout, viewSettings);

            var deactivator = viewModel as IDeactivate;

            if (deactivator != null)
            {
                RoutedEventHandler closed = null;
                closed = (s, e) => {
                    settingsFlyout.Unloaded -= closed;
                    deactivator.Deactivate(true);
                };

                settingsFlyout.Unloaded += closed;
            }

            var activator = viewModel as IActivate;

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

            if (independent)
            {
                settingsFlyout.ShowIndependent();
            }
            else
            {
                settingsFlyout.Show();
            }
        }
Example #12
0
        /// <summary>
        /// Shows a modal dialog for the specified model.
        /// </summary>
        /// <param name="rootModel">The root model.</param>
        /// <param name="context">The context.</param>
        public void ShowDialog(object rootModel, object context = null)
        {
            var view = EnsureWindow(rootModel, ViewLocator.LocateForModel(rootModel, null, context));

            ViewModelBinder.Bind(rootModel, view, context);

            var haveDisplayName = rootModel as IHaveDisplayName;

            if (haveDisplayName != null && !ConventionManager.HasBinding(view, ChildWindow.TitleProperty))
            {
                var binding = new Binding("DisplayName")
                {
                    Mode = BindingMode.TwoWay
                };
                view.SetBinding(ChildWindow.TitleProperty, binding);
            }

            var activatable = rootModel as IActivate;

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

            var deactivatable = rootModel as IDeactivate;

            if (deactivatable != null)
            {
                bool deactivatingFromView = false;
                bool deactivateFromVM     = false;

                view.Closed += (s, e) => {
                    if (deactivateFromVM)
                    {
                        return;
                    }

                    deactivatingFromView = true;
                    deactivatable.Deactivate(true);
                    deactivatingFromView = false;
                };

                deactivatable.Deactivated += (s, e) => {
                    if (e.WasClosed && !deactivatingFromView)
                    {
                        deactivateFromVM = true;
                        actuallyClosing  = true;
                        view.Close();
                        actuallyClosing  = false;
                        deactivateFromVM = false;
                    }
                };
            }

            var guard = rootModel as IGuardClose;

            if (guard != null)
            {
                view.Closing += (s, e) => OnShutdownAttempted(guard, view, e);
            }

            view.Show();
        }
        /// <summary>
        /// Shows a settings flyout panel for the specified model.
        /// </summary>
        /// <param name="viewModel">The settings view model.</param>
        /// <param name="commandLabel">The settings command label.</param>
        /// <param name="viewSettings">The optional dialog settings.</param>
        public async void ShowSettingsFlyout(object viewModel, string commandLabel, IDictionary <string, object> viewSettings = null)
        {
            var view = ViewLocator.LocateForModel(viewModel, null, null);

            ViewModelBinder.Bind(viewModel, view, null);

            viewSettings = viewSettings ?? new Dictionary <string, object>();

            var width = viewSettings.ContainsKey("width")
                            ? (SettingsFlyout.SettingsFlyoutWidth)viewSettings["width"]
                            : SettingsFlyout.SettingsFlyoutWidth.Narrow;

            // extract the header color/logo from the appmanifest.xml
            var visualElements = await Callisto.Controls.Common.AppManifestHelper.GetManifestVisualElementsAsync();

            // enable the overriding of these, but default to manifest
            var headerBackground = viewSettings.ContainsKey("headerbackground")
                                       ? (SolidColorBrush)viewSettings["headerbackground"]
                                       : new SolidColorBrush(visualElements.BackgroundColor);

            var smallLogoUri = viewSettings.ContainsKey("smalllogouri")
                                   ? (Uri)viewSettings["smalllogouri"]
                                   : visualElements.SmallLogoUri;

            var smallLogo = new BitmapImage(smallLogoUri);

            // use real property names for ApplySettings
            if (!viewSettings.ContainsKey("FlyoutWidth"))
            {
                viewSettings["FlyoutWidth"] = width;
            }
            if (!viewSettings.ContainsKey("HeaderBrush"))
            {
                viewSettings["HeaderBrush"] = headerBackground;
            }
            if (!viewSettings.ContainsKey("SmallLogoImageSource"))
            {
                viewSettings["SmallLogoImageSource"] = smallLogo;
            }

            var settingsFlyout = new SettingsFlyout
            {
                HeaderText = commandLabel,
                Content    = view,
            };

            ApplySettings(settingsFlyout, viewSettings);
            settingsFlyout.IsOpen = true;

            var deactivator = viewModel as IDeactivate;

            if (deactivator != null)
            {
                EventHandler <object> closed = null;
                closed = (s, e) => {
                    settingsFlyout.Closed -= closed;
                    deactivator.Deactivate(true);
                };

                settingsFlyout.Closed += closed;
            }

            var activator = viewModel as IActivate;

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