public async Task ShowDialog(IDialogViewModel viewModel) { var view = ViewLocator.LocateForModel(viewModel, null, null) as UserControl; view.Loaded += (sender, args) => { ViewModelBinder.Bind(viewModel, view, null); }; var dialog = new CustomMetroDialog(); dialog.MainContent.Content = view; _currentlyShownDialog = dialog; await MetroWindow.ShowMetroDialogAsync(dialog); await viewModel.Task; await MetroWindow.HideMetroDialogAsync(dialog); }
private static void VMChanged(BindableObject bindable, object oldValue, object newValue) { if (newValue == null) { return; } var vm = (Screen)newValue; //var view = vm.GetView(); var vmView = ViewLocator.LocateForModel(vm, null, null); if (vmView == null) { throw new Exception("没有找到视图"); } ViewModelBinder.Bind(vm, vmView, null); var activator = vm as IActivate; if (activator != null) { activator.Activate(); } var page = (ViewLocatorPage)bindable; if (null != (ContentPage)vmView) { var vp = (ContentPage)vmView; page.Content = vp.Content; if (vp.ToolbarItems != null) { foreach (var t in vp.ToolbarItems) { page.ToolbarItems.Add(t); } } } else if (null != (Xamarin.Forms.View)vmView) { page.Content = (Xamarin.Forms.View)vmView; } }
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); }
private MesCommandHandlerWrapper GetCommandHandlerForLayoutItem(MesCommandDefinitionBase commandDefinition, object activeItemViewModel) { #warning GetCommandHendlerForLayoutItem #if false var activeItemView = ViewLocator.LocateForModel(activeItemViewModel, null, null); var activeItemWindow = Window.GetWindow(activeItemView); if (activeItemWindow == null) { return(null); } var startElement = FocusManager.GetFocusedElement(activeItemView) ?? activeItemView; // First, we look at the currently focused element, and iterate up through // the tree, giving each DataContext a chance to handle the command. return(FindCommandHandlerInVisualTree(commandDefinition, startElement)); #endif throw new NotImplementedException(); }
private static Page GetPage(Screen vm) { var vmView = ViewLocator.LocateForModel(vm, null, null); if (vmView == null) { throw new Exception("没有找到视图"); } ViewModelBinder.Bind(vm, vmView, null); var activator = vm as IActivate; if (activator != null) { activator.Activate(); } return((Page)vmView); }
private 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); ViewModelBinder.Bind(args.NewValue, view, context); SetContentProperty(targetLocation, view); } else { SetContentProperty(targetLocation, args.NewValue); } }
/// <summary> /// Initializes the singleton application object. This is the first line of authored code /// executed, and as such is the logical equivalent of main() or WinMain(). /// </summary> public App() { this.InitializeComponent(); this._bootstrapper = new UWPBootstrapper(() => { this.Initialize(); var shellViewModel = ServiceLocator.Current.GetInstance <IShellViewModel>(); var uiElement = ViewLocator.LocateForModel(shellViewModel, null, null); ViewModelBinder.Bind(shellViewModel, uiElement, null); var activate = shellViewModel as IActivate; activate?.Activate(); Window.Current.Content = uiElement; Window.Current.Activate(); }); }
public static DockingWindow CreateWindow(this DockSite dockSite, object viewModel, bool isDocumentWindow = true, object context = null) { var view = dockSite.EnsureWindow(viewModel, ViewLocator.LocateForModel(viewModel, null, context), isDocumentWindow); ViewModelBinder.Bind(viewModel, view, context); var haveDisplayName = viewModel as IHaveDisplayName; if (haveDisplayName != null && !ConventionManager.HasBinding(view, HeaderedContentControl.HeaderProperty)) { var binding = new Binding("DisplayName") { Mode = BindingMode.TwoWay }; view.SetBinding(HeaderedContentControl.HeaderProperty, binding); } new DockableWindowConductor(dockSite, viewModel, view); return(view); }
protected async Task Start() { session.Flush(); var loaded = new SemaphoreSlim(0, 1); dispatcher = WpfTestHelper.WithDispatcher(() => { Env.TplUiScheduler = TaskScheduler.FromCurrentSynchronizationContext(); //wpf обеспечивает синхронизацию объектов ui //тк сам тест запускает в отдельной нитке то в статических полях StyleHelper могут содержаться объекты созданные //в других нитках что бы избежать ошибок очищаем статические структуры StyleHelper.Reset(); activeWindow = (Window)ViewLocator.LocateForModel(shell, null, null); //такой размер нужен что бы уместились все кнопки на панели инструментов //тк невидимую кнопку нельзя нажать activeWindow.Width = 1014; activeWindow.Height = 764; windows.Add(activeWindow); activeWindow.Loaded += (sender, args) => loaded.Release(); ViewModelBinder.Bind(shell, activeWindow, null); //что бы тесты не лезли на первый план activeWindow.ShowActivated = false; activeWindow.ShowInTaskbar = false; activeWindow.Show(); }); Env.UiScheduler = new MixedScheduler((TestScheduler)Env.UiScheduler, new DispatcherScheduler(dispatcher)); dispatcher.UnhandledException += (sender, args) => { args.Handled = true; //ошибки отмены могут возникнуть если мы закроем форму до завершения всех запросов //игнорируем их if (!(args.Exception is TaskCanceledException)) { exceptions.Add(args.Exception); } }; await loaded.WaitAsync(); WaitIdle(); }
/// <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 Window CreateWindow(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 (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); new WindowConductor(rootModel, view); return(view); }
public async Task <T> ShowSelectionDialogAsync <T>(string title, string header, IEnumerable <T> options) { var viewModel = new SelectionDialogViewModel <T>(header, options); var view = ViewLocator.LocateForModel(viewModel, null, null); ViewModelBinder.Bind(viewModel, view, null); var dialog = new ContentDialog { Content = view, IsPrimaryButtonEnabled = true, PrimaryButtonText = "Ok", IsSecondaryButtonEnabled = true, SecondaryButtonText = "Cancel", Title = title }; var result = await dialog.ShowAsync(); return(result == ContentDialogResult.Primary ? viewModel.SelectedOption : default(T)); }
public async Task <TResult> ShowDialog <TResult>(DialogViewModel <TResult> dialogViewModel) { var view = ViewLocator.LocateForModel(dialogViewModel, null, null); var dialog = view as BaseMetroDialog; if (dialog == null) { throw new ArgumentException(String.Format("The view linked to the dialog view model {0} should inherit from BaseMetroDialog.", dialogViewModel.GetType())); } ViewModelBinder.Bind(dialogViewModel, dialog, null); var window = GetMainWindow(); await window.ShowMetroDialogAsync(dialog); var result = await dialogViewModel.Task; await window.HideMetroDialogAsync(dialog); return(result); }
private static ContentPane CreateDockable(object rootModel, object context) { var view = EnsureDockWindow(ViewLocator.LocateForModel(rootModel, null, context)); ViewModelBinder.Bind(rootModel, view, context); var haveDisplayName = rootModel as IHaveDisplayName; if (haveDisplayName != null && !ConventionManager.HasBinding(view, HeaderedContentControl.HeaderProperty)) { Binding binding = new Binding("DisplayName") { Mode = BindingMode.TwoWay }; view.SetBinding(HeaderedContentControl.HeaderProperty, binding); } // ReSharper disable once ObjectCreationAsStatement new DockableWindowConductor(rootModel, view); return(view); }
UIElement GetView(object viewModel) { if (viewModel == null) { return(null); } UIElement view = Children .OfType <FrameworkElement>() .FirstOrDefault(fe => ReferenceEquals(fe.DataContext, viewModel)); if (view != null) { return(view); } var context = View.GetContext(this); view = ViewLocator.LocateForModel(viewModel, this, context); ViewModelBinder.Bind(viewModel, view, context); return(view); }
public void NavigateToType(Type value) { if (value == null || !typeof(PageViewModel).IsAssignableFrom(value)) { return; } if (_existingViewModels.TryGetValue(value, out var viewModel) && _existingViews.TryGetValue(value, out var view)) { ActivePage = view; ActivateItem(viewModel); } else { var vm = _resolver.Resolve <PageViewModel>(value); ActivePage = (PageView)ViewLocator.LocateForModel(vm, null, null); ViewModelBinder.Bind(vm, ActivePage, null); ActivateItem(vm); _existingViewModels.Add(value, vm); _existingViews.Add(value, ActivePage); } }
/// <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 = this.CreatePopup(rootModel, settings); var view = ViewLocator.LocateForModel(rootModel, popup, context); popup.Child = view; popup.SetValue(View.IsGeneratedProperty, true); ViewModelBinder.Bind(rootModel, popup, null); Caliburn.Micro.Action.SetTargetWithoutContext(view, rootModel); var activatable = rootModel as IActivate; activatable?.Activate(); if (rootModel is IDeactivate deactivator) { popup.Closed += delegate { deactivator.Deactivate(true); }; } popup.IsOpen = true; popup.CaptureMouse(); }
/// <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 = this.CreatePopup(rootModel, settings); var view = ViewLocator.LocateForModel(rootModel, popup, context); popup.Child = view; popup.SetValue(View.IsGeneratedProperty, true); ViewModelBinder.Bind(rootModel, popup, null); Caliburn.Micro.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(); }
public static Views.View LocateViewForModel(object viewModel) { Views.View view = (Views.View)ViewLocator.LocateForModel(viewModel, null, null); ViewModelBinder.Bind(viewModel, view, null); return(view); }