/// <summary>
        /// Mains the window initialized.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        /// <exception cref="ArgumentNullException">main Window WorkArea is <c>null</c>.</exception>
        private void MainWindowInitialized(object sender, EventArgs e)
        {
            if (this.mainWindow.WorkArea == null)
            {
                throw new ArgumentNullException("mainWindow", "No Designer!");
            }

            var workArea = this.mainWindow.WorkArea;

            // the global ApplicationCommands adding.
            // this.designerCanvas.CommandBindings.Add(new CommandBinding(ApplicationCommands.New, New_Executed));
            workArea.AddCommandBinding(ApplicationCommands.New, this.NewExecuted);
            workArea.AddCommandBinding(ApplicationCommands.Open, this.OpenExecuted);
            workArea.AddCommandBinding(ApplicationCommands.Save, this.SaveExecuted, this.SaveEnabled);
            workArea.AddCommandBinding(ApplicationCommands.Print, this.PrintExecuted);

            // this.designerCanvas.CommandBindings.Add(new CommandBinding(this.PasteCommand, this.Paste_Executed, Paste_Enabled));
            workArea.AddCommandBinding(ApplicationCommands.Cut, this.CutExecuted, this.CutEnabled);
            workArea.AddCommandBinding(ApplicationCommands.Copy, this.CopyExecuted, this.CopyEnabled);
            workArea.AddCommandBinding(ApplicationCommands.Paste, this.PasteExecuted, this.Paste_Enabled);
            workArea.AddCommandBinding(ApplicationCommands.Delete, this.DeleteExecuted, this.DeleteEnabled);

            // this.designerCanvas.CommandBindings.Add(new CommandBinding(SelectAllCommand, SelectAll_Executed));
            // SelectAllCommand.InputGestures.Add(new KeyGesture(Key.A, ModifierKeys.Control));
            // System.Windows.Input.KeyBinding f = new KeyBinding(
            // mainWindow.InputBindings.Add(new KeyBinding(this.SelectAllCommand, new KeyGesture(Key.A, ModifierKeys.Control)));
            this.mainWindow.InputBindings.Add(new KeyBinding(this.CancelCommand, new KeyGesture(Key.Escape)));

            // Apply KeyGestures from Attributes.
            CommandKeyGestureAttribute.ApplyKeyGestures(GetType(), this.mainWindow, this);

            // and finally detach from the Initialized event.
            this.mainWindow.Initialized -= this.MainWindowInitialized;
        }
        public void ApplyKeyGesturesTest()
        {
            var       instance     = new MyClass();
            Type      type         = instance.GetType();
            UIElement inputBinder  = instance.mainWindow;
            UIElement inputBinder2 = instance.subWindow;

            Assert.IsEmpty(inputBinder.InputBindings);
            Assert.IsEmpty(((RelayCommand)instance.FirstCommand).InputGestures);
            Assert.IsEmpty(inputBinder2.InputBindings);
            Assert.IsEmpty(((RelayCommand)instance.SecondCommand).InputGestures);

            // Apply gestures from "mainWindow"-targets to the mainWindow field.
            CommandKeyGestureAttribute.ApplyKeyGestures(type, inputBinder, instance);

            Assert.IsNotEmpty(inputBinder.InputBindings);
            Assert.AreEqual(1, inputBinder.InputBindings.Count);
            var inpBinding = inputBinder.InputBindings[0];

            Assert.AreSame(instance.FirstCommand, inpBinding.Command);
            var gesture = (KeyGesture)inpBinding.Gesture;

            Assert.AreEqual(Key.A, gesture.Key);
            Assert.AreEqual(ModifierKeys.Control, gesture.Modifiers);

            var rlay = (RelayCommand)instance.FirstCommand;

            Assert.IsNotEmpty(rlay.InputGestures);
            Assert.AreEqual(1, rlay.InputGestures.Count);
            var inpGesture = rlay.InputGestures[0];

            gesture = (KeyGesture)inpGesture;
            Assert.AreEqual(Key.A, gesture.Key);
            Assert.AreEqual(ModifierKeys.Control, gesture.Modifiers);

            Assert.IsEmpty(inputBinder2.InputBindings);
            Assert.IsEmpty(((RelayCommand)instance.SecondCommand).InputGestures);

            // Apply gestures from "subWindow"-targets to the subWindow field.
            CommandKeyGestureAttribute.ApplyKeyGestures(type, inputBinder2, instance);

            Assert.IsNotEmpty(inputBinder2.InputBindings);
            Assert.AreEqual(1, inputBinder2.InputBindings.Count);
            inpBinding = inputBinder2.InputBindings[0];
            Assert.AreSame(instance.SecondCommand, inpBinding.Command);
            gesture = (KeyGesture)inpBinding.Gesture;
            Assert.AreEqual(Key.B, gesture.Key);
            Assert.AreEqual(ModifierKeys.Alt, gesture.Modifiers);

            rlay = (RelayCommand)instance.SecondCommand;
            Assert.IsNotEmpty(rlay.InputGestures);
            Assert.AreEqual(1, rlay.InputGestures.Count);
            inpGesture = rlay.InputGestures[0];
            gesture    = (KeyGesture)inpGesture;
            Assert.AreEqual(Key.B, gesture.Key);
            Assert.AreEqual(ModifierKeys.Alt, gesture.Modifiers);
        }
        public void ApplyKeyGesturesTest1()
        {
            // Todo: MockMe
            Type          type        = null; // TODO: Initialize to an appropriate value
            ICanInputBind inputBinder = null; // TODO: Initialize to an appropriate value
            object        instance    = null; // TODO: Initialize to an appropriate value

            CommandKeyGestureAttribute.ApplyKeyGestures(type, inputBinder, instance);
            Assert.Inconclusive("A method that does not return a value cannot be verified.");
        }
        public void CommandKeyGestureAttributeConstructorTest2()
        {
            const Key key    = Key.F1;
            var       target = new CommandKeyGestureAttribute(key);

            Assert.AreEqual(key, target.Key.Key);
            Assert.AreEqual(ModifierKeys.None, target.Key.Modifiers);
            Assert.AreEqual(string.Empty, target.Key.DisplayString);
            Assert.IsNull(target.Target);
        }
        public void CommandKeyGestureAttributeConstructorTest3()
        {
            const Key          key       = Key.A;
            const ModifierKeys modifiers = ModifierKeys.Alt;
            var target = new CommandKeyGestureAttribute(key, modifiers);

            Assert.AreEqual(key, target.Key.Key);
            Assert.AreEqual(modifiers, target.Key.Modifiers);
            Assert.AreEqual(string.Empty, target.Key.DisplayString);
            Assert.IsNull(target.Target);
        }
        public void CommandKeyGestureAttributeConstructorTest5()
        {
            var key    = new KeyGesture(Key.F1);
            var target = new CommandKeyGestureAttribute(key);

            Assert.AreEqual(key, target.Key);
            Assert.AreEqual(string.Empty, target.Key.DisplayString);
            Assert.IsNull(target.Target);

            Assert.Throws <ArgumentNullException>(() => target = new CommandKeyGestureAttribute(null));
        }
        public void CommandKeyGestureAttributeConstructorTest6()
        {
            const Key          key       = Key.D;
            const ModifierKeys modifiers = ModifierKeys.Alt | ModifierKeys.Shift;
            const string       target1   = "MyTarget";
            var target = new CommandKeyGestureAttribute(key, modifiers, target1);

            Assert.AreEqual(key, target.Key.Key);
            Assert.AreEqual(modifiers, target.Key.Modifiers);
            Assert.AreEqual(string.Empty, target.Key.DisplayString);
            Assert.AreEqual(target1, target.Target);
        }
        public void CommandKeyGestureAttributeConstructorTest4()
        {
            const Key    key     = Key.F1;
            const string target1 = "TestTarget";
            var          target  = new CommandKeyGestureAttribute(key, target1);

            Assert.AreEqual(key, target.Key.Key);
            Assert.AreEqual(ModifierKeys.None, target.Key.Modifiers);
            Assert.AreEqual(string.Empty, target.Key.DisplayString);
            Assert.AreEqual(target1, target.Target);

            Assert.Throws <ArgumentNullException>(() => target = new CommandKeyGestureAttribute(null, target1));
        }