/// <summary> /// Subscribes to keyboard events. /// </summary> /// <param name="view">The view.</param> /// <exception cref="ArgumentNullException">The <paramref name="view"/> is <c>null</c>.</exception> public void SubscribeToKeyboardEvents(FrameworkElement view) { Argument.IsNotNull("view", view); CommandManagerWrapper commandManagerWrapper = null; if (!_subscribedViews.TryGetValue(view, out commandManagerWrapper)) { _subscribedViews.Add(view, new CommandManagerWrapper(view, this)); } }
/// <summary> /// Subscribes to keyboard events. /// </summary> public void SubscribeToKeyboardEvents() { #if SL5 if (_subscribedToKeyboardEvent) { return; } #endif #if NET || SILVERLIGHT var application = Application.Current; if (application == null) { Log.Warning("Application.Current is null, cannot subscribe to keyboard events"); return; } #endif #if NET FrameworkElement mainView = application.MainWindow; if (mainView == null) { if (!_subscribedToApplicationActivedEvent) { application.Activated += (sender, e) => SubscribeToKeyboardEvents(); _subscribedToApplicationActivedEvent = true; Log.Info("Application.MainWindow is null, cannot subscribe to keyboard events, subscribed to Application.Activated event"); } return; } #elif SILVERLIGHT var mainView = application.RootVisual as FrameworkElement; if (mainView == null) { Log.Warning("Application.RootVisual is null, cannot subscribe to keyboard events"); return; } _subscribedToKeyboardEvent = true; #elif NETFX_CORE // TODO: Grab events #endif #if NET || SL5 CommandManagerWrapper commandManagerWrapper = null; if (!_subscribedViews.TryGetValue(mainView, out commandManagerWrapper)) { _subscribedViews.Add(mainView, new CommandManagerWrapper(mainView, this)); } #endif }
/// <summary> /// Subscribes to keyboard events. /// </summary> /// <param name="view">The view.</param> /// <exception cref="ArgumentNullException">The <paramref name="view"/> is <c>null</c>.</exception> public void SubscribeToKeyboardEvents(FrameworkElement view) { Argument.IsNotNull("view", view); CommandManagerWrapper commandManagerWrapper = null; if (!_subscribedViews.TryGetValue(view, out commandManagerWrapper)) { _subscribedViews.Add(view, new CommandManagerWrapper(view, this)); var app = Application.Current; if (app != null) { var mainWindow = app.MainWindow; if (ReferenceEquals(mainWindow, view)) { EventManager.RegisterClassHandler(typeof(Window), Window.LoadedEvent, new RoutedEventHandler(OnWindowLoaded)); } } } }
/// <summary> /// Subscribes to keyboard events. /// </summary> /// <param name="view">The view.</param> /// <exception cref="ArgumentNullException">The <paramref name="view"/> is <c>null</c>.</exception> public void SubscribeToKeyboardEvents(FrameworkElement view) { Argument.IsNotNull("view", view); CommandManagerWrapper commandManagerWrapper = null; if (!_subscribedViews.TryGetValue(view, out commandManagerWrapper)) { // Note: also check for dispatcher, see https://github.com/Catel/Catel/issues/1205 var app = Application.Current; var dispatcher = Dispatcher.CurrentDispatcher; if (app != null && ReferenceEquals(app.Dispatcher, dispatcher)) { _subscribedViews.Add(view, new CommandManagerWrapper(view, this)); var mainWindow = app.MainWindow; if (ReferenceEquals(mainWindow, view)) { EventManager.RegisterClassHandler(typeof(Window), Window.LoadedEvent, new RoutedEventHandler(OnWindowLoaded)); } } } }