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); var context = string.IsNullOrEmpty(fe.Name) ? fe.GetHashCode().ToString() : fe.Name; ViewModelBinder.Bind(target, d, context); }); }
static void SetTargetCore(DependencyPropertyChangedEventArgs e, DependencyObject d, bool setContext) { if (e.NewValue == e.OldValue || (Execute.InDesignMode && e.NewValue is string)) { return; } var target = e.NewValue; var containerKey = e.NewValue as string; if (containerKey != null) { target = IoC.GetInstance(null, containerKey); } #if XFORMS Log.Info("Attaching message handler {0} to {1}.", target, d); Message.SetHandler(d, target); if (setContext && d is FrameworkElement) { Log.Info("Setting DC of {0} to {1}.", d, target); ((FrameworkElement)d).BindingContext = target; } #else if (setContext && d is FrameworkElement) { Log.Info("Setting DC of {0} to {1}.", d, target); ((FrameworkElement)d).DataContext = target; } Log.Info("Attaching message handler {0} to {1}.", target, d); Message.SetHandler(d, target); #endif }
static void ModelChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { if (Bootstrapper.IsInDesignMode || e.NewValue == null || e.NewValue == e.OldValue) { return; } var fe = d as FrameworkElement; if (fe == null) { return; } RoutedEventHandler handler = null; handler = delegate { var target = e.NewValue; var containerKey = e.NewValue as string; if (containerKey != null) { target = IoC.GetInstance(null, containerKey); } d.SetValue(View.IsLoadedProperty, true); ViewModelBinder.Bind(target, d, null); fe.Loaded -= handler; }; fe.Loaded += handler; }
static void ModelWithoutContextChanged(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; var containerKey = e.NewValue as string; if (containerKey != null) { LogManager.GetLog(typeof(Bind)).Info("Using IoC is deprecated and will be removed in v3.0"); target = IoC.GetInstance(null, containerKey); } d.SetValue(View.IsScopeRootProperty, true); var context = string.IsNullOrEmpty(fe.Name) ? fe.GetHashCode().ToString() : fe.Name; d.SetValue(NoContextProperty, true); ViewModelBinder.Bind(target, d, context); }); }
/// <summary> /// Called when the command was selected in the Settings Charm. /// </summary> public override void OnSelected() { var viewModel = IoC.GetInstance(ViewModelType, null); if (viewModel == null) { return; } settingsWindowManager.ShowSettingsFlyout(viewModel, Label, ViewSettings); }
/// <summary> /// Called when a settings command was selected in the Settings Charm. /// </summary> /// <param name="command">The settings command.</param> protected virtual void OnCommandSelected(CaliburnSettingsCommand command) { var viewModel = IoC.GetInstance(command.ViewModelType, null); if (viewModel == null) { return; } settingsWindowManager.ShowSettingsFlyout(viewModel, command.Label, command.ViewSettings); }
/// <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 static void DisplayRootViewFor(Type viewModelType) { IWindowManager windowManager; try { windowManager = IoC.Get <IWindowManager>(); } catch { windowManager = new WindowManager(); } windowManager.ShowWindow(IoC.GetInstance(viewModelType, null)); }
/// <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; }
/// <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> /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param> /// <returns>A task that represents the asynchronous operation.</returns> protected async Task DisplayRootViewForAsync(Type viewModelType, CancellationToken cancellationToken) { Initialize(); var viewModel = IoC.GetInstance(viewModelType, null); var view = ViewLocator.LocateForModel(viewModel, null, null); ViewModelBinder.Bind(viewModel, view, null); if (viewModel is IActivate activator) { await activator.ActivateAsync(cancellationToken); } 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 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; }
/// <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; }
private static void SetTargetCore(DependencyPropertyChangedEventArgs e, DependencyObject d, bool setContext) { if (Bootstrapper.IsInDesignMode || e.NewValue == e.OldValue || e.NewValue == null) { return; } var target = e.NewValue; var containerKey = e.NewValue as string; if (containerKey != null) { target = IoC.GetInstance(null, containerKey); } if (setContext && d is FrameworkElement) { Log.Info("Setting DC of {0} to {1}.", d, target); ((FrameworkElement)d).DataContext = target; } Log.Info("Attaching message handler {0} to {1}.", target, d); Message.SetHandler(d, target); }
/// <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> /// <param name="settings">The optional window settings.</param> protected void DisplayRootViewFor(Type viewModelType, IDictionary <string, object> settings = null) { var windowManager = IoC.Get <IWindowManager>(); windowManager.ShowWindow(IoC.GetInstance(viewModelType, null), null, settings); }
/// <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> /// <param name="settings">The optional window settings.</param> protected async Task DisplayRootViewForAsync(Type viewModelType, IDictionary <string, object> settings = null) { var windowManager = IoC.Get <IWindowManager>(); await windowManager.ShowWindowAsync(IoC.GetInstance(viewModelType, null), null, settings); }
/// <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 windowManager = IoC.Get <IWindowManager>(); windowManager.ShowWindow(IoC.GetInstance(viewModelType, null)); }