protected virtual void OnNavigated(object sender, NavigationEventArgs e)
        {
            if (e.Uri.IsAbsoluteUri || e.Content == null)
            {
                return;
            }

            ViewLocator.InitializeComponent(e.Content);

            var viewModel = ViewModelLocator.LocateForView(e.Content);

            if (viewModel == null)
            {
                return;
            }

            var page = e.Content as Page;

            if (page == null)
            {
                throw new ArgumentException("View '" + e.Content.GetType().FullName + "' should inherit from PhoneApplicationPage or one of its descendents.");
            }

            TryInjectQueryString(viewModel, page);
            ViewModelBinder.Bind(viewModel, page, null);

            var activator = viewModel as IActivate;

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

            GC.Collect();
        }
示例#2
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
        }
        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();
            }
        }
示例#4
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);
        }
示例#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);
                // 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);
            }
        }
示例#6
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);
        }
示例#7
0
        public void Open_shell()
        {
            var view = new ShellView();

            ((IViewAware)shell).AttachView(new CatalogOfferView());
            ViewModelBinder.Bind(shell, view, null);
        }
示例#8
0
        private UIElement GetBindViewByViewModel(IViewModel viewModel)
        {
            if (viewModel == null)
            {
                throw new ArgumentNullException("viewModel");
            }

            UIElement view;
            var       key = viewModel.GetType();

            if (_views.ContainsKey(key))
            {
                view = _views[key];
                _views.Remove(key);
            }
            else
            {
                view = ViewLocator.LocateForModel(viewModel, null, null);
            }
            if (view == null)
            {
                throw new DeveloperException(string.Format("Can't find view for view model {0}", viewModel));
            }

            ViewModelBinder.Bind(viewModel, view, null);

            return(view);
        }
示例#9
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);
            });
        }
示例#10
0
 public void Init()
 {
     UpdateTitles(ManagedFormHost.Runtime.Session);
     ViewModelBinder.Bind(new ExitDialogModel {
         Host = ManagedFormHost
     }, this, null);
 }
        /// <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 });
        }
示例#12
0
        public static async Task <object> ShowDialog(object viewModel)
        {
            UserControl view = ViewLocator.LocateForModel(viewModel, null, null) as UserControl;

            ViewModelBinder.Bind(viewModel, view, null);
            return(await DialogHost.Show(view));
        }
        public async Task RenameLayout(LayoutStructure layoutStructure)
        {
            var vm   = IoC.Get <RenameViewModel>();
            var view = ViewLocator.LocateForModel(vm, null, null);

            vm.Name = layoutStructure.Name;
            vm.Init();

            ViewModelBinder.Bind(vm, view, null);

            var result = await DialogHost.Show(view, _dialogIdentifier);

            if ((bool)result)
            {
                var serializedStructure = LayoutManager.SerializeStructure(layoutStructure);
                layoutStructure.Name = vm.Name;
                var renamedSerializedStructure = LayoutManager.SerializeStructure(layoutStructure);

                if (_configurationService.ActiveConfiguration.Layouts.Contains(serializedStructure))
                {
                    var index = _configurationService.ActiveConfiguration.Layouts.IndexOf(serializedStructure);
                    _configurationService.ActiveConfiguration.Layouts.Remove(serializedStructure);
                    _configurationService.ActiveConfiguration.Layouts.Insert(index, renamedSerializedStructure);
                    _configurationService.Save();
                }

                await _eventAggregator.PublishOnUIThreadAsync(new LayoutsChanged());
            }
        }
        public void OpenSettings()
        {
            IsMenuOpen = false;

            var dialogViewModel = IoC.Get <SettingsViewModel>();
            var dialogView      = ViewLocator.LocateForModel(dialogViewModel, null, null);

            ViewModelBinder.Bind(dialogViewModel, dialogView, null);

            var previousLanguage = _configurationService.ActiveConfiguration.Language;

            dialogViewModel.Init(_configurationService.ActiveConfiguration, true);
            if (_dialogManager.ShowDialog(dialogViewModel, dialogViewModel.WindowSettings))
            {
                _configurationService.UpdateConfiguration(_configurationService.ActiveConfiguration.Name, dialogViewModel.Configuration);
                if (previousLanguage != _configurationService.ActiveConfiguration.Language)
                {
                    if (_dialogManager.ShowMessageBox(Translations.DoYouWantToChangeTheLanguageNowMessage, Translations.Language, Contract.Services.MessageBoxOptions.YesNo))
                    {
                        _layoutManager.Reload();
                    }
                }
            }
            else
            {
                dialogViewModel.RestoreColors();
            }
        }
示例#15
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);
        }
        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;
            }
        }
示例#17
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);
        }
        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 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);
                }
            }
示例#20
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));
        }
示例#21
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;
            }
        }
        public override void Execute()
        {
            OptionsDialog dialog = new OptionsDialog();

            ViewModelBinder.Bind(IoC.Get <IOptionService>(), dialog, null);
            dialog.ShowDialog();
        }
        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);
        }
        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);
        }
示例#25
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);
        }
示例#26
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var view = (FrameworkElement)PiracRunner.GetViewForViewModel(value);

            ViewModelBinder.Bind(view, value);
            return(view);
        }
示例#27
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);
            });
        }
示例#28
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";
        }
        public AppView()
        {
            InitializeComponent();

            //// Load the three dynamic views - it's terrible to do this
            //// in code behind, but honestly... it's a pretty simple
            //// application... so maybe I can be a bit lazy.

            // The about view does not need to be called here since we'll
            // be doing that properly in the view itself.

            // Settings View
            SettingsView      sv  = new SettingsView();
            SettingsViewModel svm = new SettingsViewModel();

            ViewModelBinder.Bind(svm, sv, null);
            Settings.Tag = sv;

            // Devices View
            DevicesView      dv  = new DevicesView();
            DevicesViewModel dvm = new DevicesViewModel();

            ViewModelBinder.Bind(dvm, dv, null);
            Devices.Tag = dv;

            // Users View
            UsersView      uv  = new UsersView();
            UsersViewModel uvm = new UsersViewModel();

            ViewModelBinder.Bind(uvm, uv, null);
            Users.Tag = uv;
        }
示例#30
0
        private static UIElement LocateAndBindView(object rootModel, object context)
        {
            var view = ViewLocator.LocateForModel(rootModel, null, context);

            ViewModelBinder.Bind(rootModel, view, context);

            return(view);
        }