示例#1
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 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);

            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();
        }
示例#2
0
        static void ModelChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            if (Execute.InDesignMode || e.NewValue == null || e.NewValue == e.OldValue)
            {
                return;
            }

            var fe = d as FrameworkElement;

            if (fe == null)
            {
                return;
            }

            View.ExecuteOnLoad(fe, delegate {
                var target       = e.NewValue;
                var containerKey = e.NewValue as string;

                if (containerKey != null)
                {
                    target = IoC.GetInstance(null, containerKey);
                }

                d.SetValue(View.IsScopeRootProperty, true);

                string context = string.IsNullOrEmpty(fe.Name)
                    ? fe.GetHashCode().ToString()
                    : fe.Name;

                ViewModelBinder.Bind(target, d, context);
            });
        }
示例#3
0
        /// <summary>
        /// Creates the page.
        /// </summary>
        /// <param name="rootModel">The root model.</param>
        /// <param name="context">The context.</param>
        /// <returns></returns>
        public virtual Page CreatePage(object rootModel, object context)
        {
            var view = EnsurePage(rootModel, ViewLocator.LocateForModel(rootModel, null, context));

            ViewModelBinder.Bind(rootModel, view, context);

            var haveDisplayName = rootModel as IHaveDisplayName;

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

            var activatable = rootModel as IActivate;

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

            var deactivatable = rootModel as IDeactivate;

            if (deactivatable != null)
            {
                view.Unloaded += (s, e) => deactivatable.Deactivate(true);
            }

            return(view);
        }
示例#4
0
        private DocumentContent GetDocument(IDockScreen rootModel)
        {
            //see if the dockable exists
            var existingView = _dockingManager.Documents.FirstOrDefault(dc => dc.DataContext == rootModel);

            if (existingView != null)
            {
                return(existingView);
            }

            var view = ViewLocator.LocateForModel(rootModel, null, DockType.Document);

            ViewModelBinder.Bind(rootModel, view, DockType.Document);

            return(view as DocumentContent);
        }
示例#5
0
        /// <summary>
        /// Locates the view model, locates the associate view, binds them and shows it as the root view.
        /// </summary>
        /// <param name="application">The application.</param>
        /// <param name="viewModelType">The view model type.</param>
        protected static void DisplayRootViewFor(Application application, Type viewModelType)
        {
            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();
            }

            Mouse.Initialize(view);
            application.RootVisual = view;
        }
示例#6
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);
        }
示例#7
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);
            }
        }
示例#8
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);
        }
示例#9
0
文件: Bind.cs 项目: stevexy/kasicass
        static void DataContextChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            if (!Execute.InDesignMode)
            {
                return;
            }

            var enable = d.GetValue(AtDesignTimeProperty);

            if (enable == null || ((bool)enable) == false || e.NewValue == null)
            {
                return;
            }

            var fe = d as FrameworkElement;

            if (fe == null)
            {
                return;
            }

            ViewModelBinder.Bind(e.NewValue, d, string.IsNullOrEmpty(fe.Name) ? fe.GetHashCode().ToString() : fe.Name);
        }