Example #1
0
        public WpfView GetView()
        {
            System.Windows.UIElement view = null;
            WpfView retView = null;

            try
            {
                do
                {
                    view = ViewLocator.LocateForModel(this, null, null);

                    if (view == null)
                    {
                        break;
                    }
                    if (view is WpfView wpfView)
                    {
                        retView = wpfView;
                        ViewModelBinder.Bind(this, retView, null);
                    }
                } while (false);
            }
            catch (Exception e)
            {
                MessageBox.Show($"WpfViewModel::GetView -  Fail to get view of Run Parameters due to exception: {e.Message}");
            }
            return(retView);
        }
        public void Do_not_duplicate_result_subscriptions()
        {
            var shell = new Conductor <IScreen>();
            var model = new TestScreen();

            Init(model);

            WpfTestHelper.WithWindow2(async w => {
                var view = (FrameworkElement)ViewLocator.LocateForModel(shell, null, null);
                ViewModelBinder.Bind(shell, view, null);

                w.Content        = view;
                shell.ActiveItem = model;
                await view.WaitLoaded();

                shell.DeactivateItem(model, false);
                await w.WaitIdle();

                shell.ActivateItem(model);
                await w.WaitIdle();

                model.Raise();
                await w.WaitIdle();
            });

            Assert.AreEqual(1, model.ProcessedCount);
        }
Example #3
0
        public static async Task PopupAsync <T>(T vm = null) where T : class
        {
            var view = ViewLocator.LocateForModelType(typeof(T), null, null);

            if (view == null)
            {
                throw new Exception(string.Format("Can't locate view for type : {0}", typeof(T).Name));
            }

            if (!(view is PopupPage))
            {
                throw new NotSupportedException("PopupAsync only support PopupPage");
            }

            if (vm == null)
            {
                vm = IoC.Get <T>();
            }
            if (vm != null)
            {
                ViewModelBinder.Bind(vm, view, null);
            }

            await PopupNavigation.PushAsync((PopupPage)view);
        }
Example #4
0
        /// <summary>
        /// Gets the dockable window. If it doesnt exist it creates it, otherwise it returns the one with the existing view model.
        /// </summary>
        /// <param name = "rootModel">The root model.</param>
        /// <param name = "context">The context.</param>
        /// <param name = "isDocument">If set to <c>true</c>, the created window will be a document window.</param>
        /// <returns>The dockable window.</returns>
        private DockableContent GetDockable(object rootModel,
                                            object context,
                                            bool isDocument = false)
        {
            //see if the dockable exists
            var existingView = GetDockingManager().DockableContents.FirstOrDefault(dc => dc.DataContext == rootModel);

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

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

            ViewModelBinder.Bind(rootModel, view, context);
            var dockableView = EnsureDockableContent(rootModel, view, isDocument);

            //set the display name (tab title)
            dockableView.DataContext = rootModel;
            var haveDisplayName = rootModel as IHaveDisplayName;

            if (haveDisplayName != null && !ConventionManager.HasBinding(dockableView, DockableContent.TitleProperty))
            {
                dockableView.SetBinding(DockableContent.TitleProperty, "DisplayName");
            }

            new DockableContentConductor(rootModel, dockableView);
            return(dockableView);
        }
Example #5
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);

            if (!SetContentProperty(targetLocation, view))
            {
                Log.Warn("SetContentProperty failed for ViewLocator.LocateForModel, falling back to LocateForModelType");

                view = ViewLocator.LocateForModelType(model.GetType(), targetLocation, e.NewValue);

                SetContentProperty(targetLocation, view);
            }

            ViewModelBinder.Bind(model, view, e.NewValue);
        }
Example #6
0
        static void ModelChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            if (View.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;

                d.SetValue(View.IsScopeRootProperty, true);

#if XFORMS
                var context = fe.Id.ToString("N");
#else
                var context = string.IsNullOrEmpty(fe.Name)
                                  ? fe.GetHashCode().ToString()
                                  : fe.Name;
#endif

                ViewModelBinder.Bind(target, d, context);
            });
        }
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>
        /// <param name="settings">The optional popup settings.</param>
        /// <returns>The window.</returns>
        protected virtual async Task <Window> CreateWindowAsync(object rootModel, bool isDialog, object context, IDictionary <string, object> settings)
        {
            var view = this.EnsureWindow(rootModel, ViewLocator.LocateForModel(rootModel, null, context), isDialog);

            ViewModelBinder.Bind(rootModel, view, context);

            if (string.IsNullOrEmpty(view.Title) &&
                rootModel is IHaveDisplayName &&
                !ConventionManager.HasBinding(view, Window.TitleProperty))
            {
                var binding = new Binding(nameof(IHaveDisplayName.DisplayName))
                {
                    Mode = BindingMode.TwoWay
                };
                view.SetBinding(Window.TitleProperty, binding);
            }

            this.ApplySettings(view, settings);

            var conductor = new WindowConductor(rootModel, view);

            await conductor.InitialiseAsync();

            return(view);
        }
        public new void Save()
        {
            //IsBusy = true;

            _isSaving = true;
            base.Save();

            if (Error != null)
            {
                MessageBox.Show(Error.Message, "SaveError".GetUiTranslation(), MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            _refreshDateTime = DateTime.Now;

            if (_parent != null)
            {
                _parent.ListItemId = Model.RegisterId;
            }

            if (ViewNamedElements != null)
            {
                ViewModelBinder.RebindProperties(this);
            }

            NotifyOfPropertyChange("Audit");
            SetReadOnlyButtons();
            _isSaving = false;

            //IsBusy = false;

            ParentViewModel.AutoRefreshDocuments();
        }
Example #9
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var view = (FrameworkElement)PiracRunner.GetViewForViewModel(value);

            ViewModelBinder.Bind(view, value);
            return(view);
        }
Example #10
0
        public ThreeWayToggleSwitchAppearanceEditorViewModel(IEventAggregator eventAggregator, params object[] settings)
        {
            bool IsModeEditor = (bool)settings[0];

            if (IsModeEditor)
            {
                var view = ViewLocator.LocateForModel(this, null, null);
                ViewModelBinder.Bind(this, view, null);
            }
            NameUC = (string)settings[1];

            var index = 3;

            PositionImage0 = ((string[])settings[index])[0];
            PositionImage1 = ((string[])settings[index])[1];
            PositionImage2 = ((string[])settings[index])[2];

            PositionIndicatorImage0 = ((string[])settings[index])[3];
            PositionIndicatorImage1 = ((string[])settings[index])[4];
            PositionIndicatorImage2 = ((string[])settings[index++])[5];
            IndexImage = (int)settings[index++];

            Has3Images   = !string.IsNullOrEmpty(PositionImage2);
            hasIndicator = !string.IsNullOrEmpty(PositionIndicatorImage0);

            //Has3Images = true;
            //HasIndicator = false;
            this.eventAggregator = eventAggregator;
            eventAggregator.Subscribe(this);

            Name = "Appareance";
        }
        protected virtual object LoadContent(Uri uri)
        {
            // don't do anything in design mode
            if (ModernUIHelper.IsInDesignMode)
            {
                return(null);
            }

            var content = Application.LoadComponent(uri);

            if (content == null)
            {
                return(null);
            }

            var vm = ViewModelLocator.LocateForView(content);

            if (vm == null)
            {
                return(content);
            }

            if (content is DependencyObject)
            {
                ViewModelBinder.Bind(vm, content as DependencyObject, null);
            }
            return(content);
        }
Example #12
0
        public void Bind_content_elements()
        {
            var item = new Run {
                Name = "Text"
            };
            var notify = new Run {
                Name = "NotifyItems_Count"
            };

            model.Text = "123";
            model.NotifyItems.Value = new List <string>();
            var text = new TextBlock {
                Inlines =
                {
                    item,
                    notify
                }
            };

            view.Content = text;

            Assert.That(view.Descendants().Count(), Is.GreaterThan(0));
            ViewModelBinder.Bind(model, view, null);
            Assert.That(item.Text, Is.EqualTo("123"));
            Assert.IsNotNull(BindingOperations.GetBinding(notify, Run.TextProperty));
        }
        private TabItem GenerateDetailPage(TreeItemDetail treeItemDetail)
        {
            var tabItem = new TabItem
            {
                Header = new StackPanel
                {
                    Orientation = Orientation.Horizontal,
                    Children    =
                    {
                        new PackIconModern
                        {
                            Kind   = treeItemDetail.Icon,
                            Margin = new Thickness(0, 0, 5, 0)
                        },
                        new TextBlock
                        {
                            Text = treeItemDetail.GetDisplayName()
                        }
                    }
                },
                Tag = treeItemDetail
            };

            var view = ViewLocator.LocateForModel(treeItemDetail, null, null);

            ViewModelBinder.Bind(treeItemDetail, view, null);
            tabItem.Content = view;

            return(tabItem);
        }
        private static void PopulateTabControl(TabablzControl tabablzControl, LayoutStructureTabSet layoutStructureTabSet)
        {
            bool wasAnyTabSelected = false;

            foreach (var tabItem in layoutStructureTabSet.TabItems)
            {
                var view = ViewLocator.LocateForModelType(tabItem.ViewModelType, null, null);
                var vm   = typeof(IoC).GetMethod("Get").MakeGenericMethod(tabItem.ViewModelType).Invoke(tabablzControl, new Object[] { null });

                ViewModelBinder.Bind(vm, view, null);
                (tabablzControl.DataContext as ShellViewModel).ActivateItem(vm as IScreen);

                tabablzControl.AddToSource(view);

                if (tabItem.Id == layoutStructureTabSet.SelectedTabItemId)
                {
                    tabablzControl.Dispatcher.BeginInvoke(new System.Action(() =>
                    {
                        tabablzControl.SetCurrentValue(Selector.SelectedItemProperty, view);
                    }), DispatcherPriority.Loaded);
                    wasAnyTabSelected = true;
                }
            }

            if (!wasAnyTabSelected && tabablzControl.Items.Count != 0)
            {
                tabablzControl.Dispatcher.BeginInvoke(new System.Action(() =>
                {
                    tabablzControl.SetCurrentValue(Selector.SelectedItemProperty, tabablzControl.Items.OfType <System.Windows.Controls.UserControl>().First());
                }), DispatcherPriority.Loaded);
                wasAnyTabSelected = true;
            }
        }
Example #15
0
        /// <summary>
        /// Creates the page.
        /// </summary>
        /// <param name="rootModel">The root model.</param>
        /// <param name="context">The context.</param>
        /// <param name="settings">The optional popup settings.</param>
        /// <returns>The page.</returns>
        public virtual async Task <Page> CreatePageAsync(object rootModel, object context, IDictionary <string, object> settings)
        {
            var view = this.EnsurePage(rootModel, ViewLocator.LocateForModel(rootModel, null, context));

            ViewModelBinder.Bind(rootModel, view, context);

            if (string.IsNullOrEmpty(view.Title) &&
                rootModel is IHaveDisplayName haveDisplayName &&
                !ConventionManager.HasBinding(view, Page.TitleProperty))
            {
                var binding = new Binding(nameof(IHaveDisplayName.DisplayName))
                {
                    Mode = BindingMode.TwoWay
                };
                view.SetBinding(Page.TitleProperty, binding);
            }

            this.ApplySettings(view, settings);

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

            if (rootModel is IDeactivate deactivatable)
            {
                view.Unloaded += async(s, e) => await deactivatable.DeactivateAsync(true);
            }

            return(view);
        }
        protected override RadPane CreatePaneForItem(object item)
        {
            var viewModel = item as IPaneViewModel;

            if (viewModel != null)
            {
                RadPane pane;

                if (viewModel.IsDocument)
                {
                    pane = new RadDocumentPane();
                }
                else
                {
                    pane       = new RadPane();
                    pane.Width = 600;
                }
                pane.DataContext = item;
                pane.SetValue(View.IsGeneratedProperty, true);
                RadDocking.SetSerializationTag(pane, viewModel.Header);
                pane.Content = ViewLocator.LocateForModel(viewModel, null, null);
                ViewModelBinder.Bind(viewModel, pane, null);
                viewModel.IsPaneActive = true;
                viewModel.IsSelected   = true;
                return(pane);
            }
            return(base.CreatePaneForItem(item));
        }
Example #17
0
        private static Page GetPage(Screen vm)
        {
            Element vmView = null;

            try {
                vmView = ViewLocator.LocateForModel(vm, null, null);
            } catch (Exception e) {
                throw e;
            }
            if (vmView == null)
            {
                throw new Exception("没有找到视图");
            }
            ViewModelBinder.Bind(vm, vmView, null);

            var activator = vm as IActivate;

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

            ///////////
            vmView.Parent = null;

            return((Page)vmView);
        }
Example #18
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);
                // Trialing binding before setting content in Xamarin Forms
#if XFORMS
                ViewModelBinder.Bind(args.NewValue, view, context);
#endif
                if (!SetContentProperty(targetLocation, view))
                {
                    Log.Warn("SetContentProperty failed for ViewLocator.LocateForModel, falling back to LocateForModelType");

                    view = ViewLocator.LocateForModelType(args.NewValue.GetType(), targetLocation, context);

                    SetContentProperty(targetLocation, view);
                }
#if !XFORMS
                ViewModelBinder.Bind(args.NewValue, view, context);
#endif
            }
            else
            {
                SetContentProperty(targetLocation, args.NewValue);
            }
        }
            private static Page LocatePage(object o)
            {
                if (o == null)
                {
                    throw new ArgumentNullException("o");
                }

                var vmView = ViewLocator.LocateForModel(o, null, null);

                if (vmView == null)
                {
                    throw new Exception("没有找到视图");
                }
                ViewModelBinder.Bind(o, vmView, null);

                var activator = o as IActivate;

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

                var page = (Page)vmView;

                if (page != null)
                {
                    page.Title = ((Screen)o)?.DisplayName;
                    return(page);
                }
                else
                {
                    return(null);
                }
            }
Example #20
0
        /// <summary>
        /// Binds the view model.
        /// </summary>
        /// <param name="view">The view.</param>
        /// <param name="viewModel">The view model.</param>
        protected virtual async Task BindViewModel(DependencyObject view, object viewModel = null)
        {
            ViewLocator.InitializeComponent(view);
            viewModel = viewModel ?? ViewModelLocator.LocateForView(view);

            if (viewModel == null)
            {
                return;
            }

            if (treatViewAsLoaded)
            {
                view.SetValue(View.IsLoadedProperty, true);
            }

            TryInjectParameters(viewModel, CurrentParameter);
            ViewModelBinder.Bind(viewModel, view, null);

            if (viewModel is IActivate activator)
            {
                activator.Activate();
            }

            //     frame.NavigateToType(typeof(view), true, new FrameNavigationOptions() { IsNavigationStackEnabled = true });
        }
Example #21
0
        public void Open_shell()
        {
            var view = new ShellView();

            ((IViewAware)shell).AttachView(new CatalogOfferView());
            ViewModelBinder.Bind(shell, view, null);
        }
Example #22
0
        static void DataContextChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            if (!View.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;
            }
#if XFORMS
            ViewModelBinder.Bind(e.NewValue, d, fe.Id.ToString("N"));
#else
            ViewModelBinder.Bind(e.NewValue, d, string.IsNullOrEmpty(fe.Name) ? fe.GetHashCode().ToString() : fe.Name);
#endif
        }
Example #23
0
        private void OnTrayPopupOpen(object sender, RoutedEventArgs routedEventArgs)
        {
            Popup popup = _icon.TrayPopupResolved;

            var       popupViewModel = _popup;
            UIElement popupView      = _icon.TrayPopup;

            popup.SetValue(View.IsGeneratedProperty, true);
            ViewModelBinder.Bind(popupViewModel, popup, null);
            Caliburn.Micro.Action.SetTargetWithoutContext(popupView, popupViewModel);

            var activate = popupViewModel as IActivate;

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

            var deactivator = popupViewModel as IDeactivate;

            if (deactivator != null)
            {
                popup.Closed += (EventHandler)((param0, param1) => deactivator.Deactivate(true));
            }

            var trayPopup = popupViewModel as TrayPopup;

            if (trayPopup != null)
            {
                trayPopup.ParentPopup = popup;
            }
        }
Example #24
0
        private BaseDockableContent GetDockable(object rootModel, object context, DockArea dockArea, bool isDocument = false)
        {
            var docmanager = GetDockingManager();

            var existingView = docmanager.DockableContents.FirstOrDefault(dc => dc.Title == (rootModel as ViewModelBase).DisplayName) as BaseDockableContent;

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

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

            ViewModelBinder.Bind(rootModel, view, context);
            var dockableView = new BaseDockableContent(rootModel, view, dockArea, isDocument);

            //set the display name (tab title)
            var haveDisplayName = rootModel as IHaveDisplayName;

            //if (haveDisplayName != null && !ConventionManager.HasBinding(dockableView, ManagedContent.TitleProperty))
            //    dockableView.SetBinding(ManagedContent.TitleProperty, "DisplayName");
            if (haveDisplayName != null && !ConventionManager.HasBinding(dockableView, ManagedContent.TitleProperty))
            {
                dockableView.Title = (rootModel as IHaveDisplayName).DisplayName;
            }

            new DockableContentConductor(rootModel, dockableView);
            return(dockableView);
        }
Example #25
0
        ObservableCollection <UIElement> GetCollectionsInPage(IEnumerator enumerator, PageFluidPanel instance)
        {
            ObservableCollection <UIElement> collections = null;

            for (int i = 1; i <= _pageSize; i++)
            {
                if (enumerator.MoveNext())//if the current page does not have children then the collection is null.
                {
                    if (collections == null)
                    {
                        collections = new ObservableCollection <UIElement>();
                    }

                    var itemView = Activator.CreateInstance(this.ItemView.GetType()) as FrameworkElement;

                    ViewModelBinder.Bind(enumerator.Current, itemView, null);

                    //FluidMouseDragBehavior behavior = new FluidMouseDragBehavior();
                    //behavior.Attach(itemView);

                    collections.Add(itemView);
                }
            }

            return(collections);
        }
        public override void Execute()
        {
            OptionsDialog dialog = new OptionsDialog();

            ViewModelBinder.Bind(IoC.Get <IOptionService>(), dialog, null);
            dialog.ShowDialog();
        }
        public void OpenSettings(User user)
        {
            var dialogViewModel = IoC.Get <SettingsViewModel>();
            var dialogView      = ViewLocator.LocateForModel(dialogViewModel, null, null);

            ViewModelBinder.Bind(dialogViewModel, dialogView, null);

            var previousLanguage = _configurationService.ActiveConfiguration.Language;
            var isActiveConfig   = _configurationService.ActiveConfiguration == user.Configuration;

            dialogViewModel.Init(user.Configuration, isActiveConfig);
            if (_dialogManager.ShowDialog(dialogViewModel, dialogViewModel.WindowSettings))
            {
                _configurationService.UpdateConfiguration(user.Name, dialogViewModel.Configuration);
                user.Configuration = dialogViewModel.Configuration;
                if (isActiveConfig && previousLanguage != _configurationService.ActiveConfiguration.Language)
                {
                    if (_dialogManager.ShowMessageBox(Translations.DoYouWantToChangeTheLanguageNowMessage, Translations.Language, MessageBoxOptions.YesNo))
                    {
                        _layoutManager.Reload();
                    }
                }
            }
            else
            {
                dialogViewModel.RestoreColors();
            }
        }
Example #28
0
        public LayoutPropertyEditorViewModel(IEventAggregator eventAggregator, params object[] settings)
        {
            bool IsModeEditor = (bool)settings[0];

            if (IsModeEditor)
            {
                var view = ViewLocator.LocateForModel(this, null, null);
                ViewModelBinder.Bind(this, view, null);
            }

            NameUC = (string)settings[1];

            UCLeft = ((int[])settings[2])[0];
            UCTop  = ((int[])settings[2])[1];

            var width  = (double)((int[])settings[2])[2];
            var height = (double)((int[])settings[2])[3];

            SelectedSwitchRotation = (SwitchRotation)((int[])settings[2])[4];

            Factor = height / width;

            Width  = width;
            Height = height;



            this.eventAggregator = eventAggregator;
            eventAggregator.Subscribe(this);

            Name = "Layout";
        }
Example #29
0
        /// <summary>
        /// Shows a popup dialog for the specified model relative to the <paramref name="placementTarget"/>.
        /// </summary>
        /// <param name="rootModel">The root model.</param>
        /// <param name="placementTarget">The placement target.</param>
        /// <param name="viewSettings">The optional dialog settings.</param>
        public void ShowFlyout(object rootModel, UIElement placementTarget, IDictionary <string, object> viewSettings = null)
        {
            var view = ViewLocator.LocateForModel(rootModel, null, null);

            ViewModelBinder.Bind(rootModel, view, null);

            var flyout = new Flyout
            {
                Content         = view,
                PlacementTarget = placementTarget,
            };

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

            var deactivator = rootModel as IDeactivate;

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

                flyout.Closed += closed;
            }

            var activator = rootModel as IActivate;

            if (activator != null)
            {
                activator.Activate();
            }
        }
Example #30
0
        public void ShowBalloonTip(string title, string message, object viewModel = null, int timeout = 6000)
        {
            var balloonTipViewModel = new DefaultBalloonTipViewModel()
            {
                Title     = title,
                Message   = message,
                ViewModel = viewModel
            };

            this.wasVisible = this.IsVisible;
            if (!wasVisible)
            {
                balloonTipViewModel.BalloonClosing += BalloonTipViewModelOnBalloonClosing;
                IsVisible = true;
            }

            Execute.OnUIThread(
                () =>
            {
                var balloonTip = new DefaultBalloonTip()
                {
                };
                ViewModelBinder.Bind(balloonTipViewModel, balloonTip, null);
                TaskbarIcon.ShowCustomBalloon(balloonTip, PopupAnimation.Slide, timeout);
            });
        }
Example #31
0
        protected override MvvmCross.ViewModels.IMvxViewModelLocator CreateDefaultViewModelLocator()
        {
            var defaultLocator = base.CreateDefaultViewModelLocator();

            var binder = new ViewModelBinder(CreatableTypes);

            // register default view model binder
            Mvx.RegisterSingleton<IViewModelBinder>(binder);

            return new BindingViewModelLocator(defaultLocator, binder);
        }