Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / Orcas / SP / wpf / src / Core / CSharp / System / Windows / Input / Command / KeyBinding.cs / 1 / KeyBinding.cs
//---------------------------------------------------------------------------- // //// Copyright (C) Microsoft Corporation. All rights reserved. // // // // Description: The KeyBinding class is used by the developer to create Keyboard Input Bindings // // See spec at : http://avalon/coreui/Specs/Commanding(new).mht // //* KeyBinding class serves the purpose of Input Bindings for Keyboard Device. // // History: // 06/01/2003 : chandras - Created // 05/01/2004 : chandra - changed to accommodate new design // ( http://avalon/coreui/Specs/Commanding(new).mht ) //--------------------------------------------------------------------------- using System; using System.Windows.Input; using System.Windows; using System.ComponentModel; using System.Windows.Markup; using SR=MS.Internal.PresentationCore.SR; using SRID=MS.Internal.PresentationCore.SRID; namespace System.Windows.Input { ////// KeyBinding - Implements InputBinding (generic InputGesture-Command map) /// KeyBinding acts like a map for KeyGesture and Commands. /// Most of the logic is in InputBinding and KeyGesture, this only /// facilitates user to add Key/Modifiers directly without going in /// KeyGesture path. Also it provides the KeyGestureTypeConverter /// on the Gesture property to have KeyGesture, like Ctrl+X, Alt+V /// defined in Markup as Gesture="Ctrl+X" working /// public class KeyBinding : InputBinding { //----------------------------------------------------- // // Constructors // //----------------------------------------------------- #region Constructor ////// Constructor /// public KeyBinding() : base() { } ////// Constructor /// /// Command associated /// KeyGesture associated public KeyBinding(ICommand command, KeyGesture gesture) : base(command, gesture) { } ////// Constructor /// /// /// modifiers /// key public KeyBinding(ICommand command, Key key, ModifierKeys modifiers) : base(command, new KeyGesture(key, modifiers)) { } #endregion Constructor //------------------------------------------------------ // // Public Methods // //----------------------------------------------------- #region Public Methods ////// KeyGesture Override, to ensure type-safety and provide a /// TypeConverter for KeyGesture /// [TypeConverter(typeof(KeyGestureConverter))] [ValueSerializer(typeof(KeyGestureValueSerializer))] public override InputGesture Gesture { get { return base.Gesture as KeyGesture; } set { if (value is KeyGesture) { base.Gesture = value; } else { throw new ArgumentException(SR.Get(SRID.InputBinding_ExpectedInputGesture, typeof(KeyGesture))); } } } ////// Modifier /// public ModifierKeys Modifiers { get { lock (_dataLock) { if (null != Gesture) { return ((KeyGesture)Gesture).Modifiers; } return ModifierKeys.None; } } set { lock (_dataLock) { if (null == Gesture) { Gesture = new KeyGesture(Key.None, (ModifierKeys)value, /*validateGesture = */ false); } else { Gesture = new KeyGesture(((KeyGesture)Gesture).Key, value, /*validateGesture = */ false); } } } } ////// Key /// public Key Key { get { lock (_dataLock) { if (null != Gesture) { return ((KeyGesture)Gesture).Key; } return Key.None; } } set { lock (_dataLock) { if (null == Gesture) { Gesture = new KeyGesture((Key)value, ModifierKeys.None, /*validateGesture = */ false); } else { Gesture = new KeyGesture(value, ((KeyGesture)Gesture).Modifiers, /*validateGesture = */ false); } } } } #endregion Public Methods //------------------------------------------------------ // // Private Fields // //------------------------------------------------------ } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. //---------------------------------------------------------------------------- // //// Copyright (C) Microsoft Corporation. All rights reserved. // // // // Description: The KeyBinding class is used by the developer to create Keyboard Input Bindings // // See spec at : http://avalon/coreui/Specs/Commanding(new).mht // //* KeyBinding class serves the purpose of Input Bindings for Keyboard Device. // // History: // 06/01/2003 : chandras - Created // 05/01/2004 : chandra - changed to accommodate new design // ( http://avalon/coreui/Specs/Commanding(new).mht ) //--------------------------------------------------------------------------- using System; using System.Windows.Input; using System.Windows; using System.ComponentModel; using System.Windows.Markup; using SR=MS.Internal.PresentationCore.SR; using SRID=MS.Internal.PresentationCore.SRID; namespace System.Windows.Input { ////// KeyBinding - Implements InputBinding (generic InputGesture-Command map) /// KeyBinding acts like a map for KeyGesture and Commands. /// Most of the logic is in InputBinding and KeyGesture, this only /// facilitates user to add Key/Modifiers directly without going in /// KeyGesture path. Also it provides the KeyGestureTypeConverter /// on the Gesture property to have KeyGesture, like Ctrl+X, Alt+V /// defined in Markup as Gesture="Ctrl+X" working /// public class KeyBinding : InputBinding { //----------------------------------------------------- // // Constructors // //----------------------------------------------------- #region Constructor ////// Constructor /// public KeyBinding() : base() { } ////// Constructor /// /// Command associated /// KeyGesture associated public KeyBinding(ICommand command, KeyGesture gesture) : base(command, gesture) { } ////// Constructor /// /// /// modifiers /// key public KeyBinding(ICommand command, Key key, ModifierKeys modifiers) : base(command, new KeyGesture(key, modifiers)) { } #endregion Constructor //------------------------------------------------------ // // Public Methods // //----------------------------------------------------- #region Public Methods ////// KeyGesture Override, to ensure type-safety and provide a /// TypeConverter for KeyGesture /// [TypeConverter(typeof(KeyGestureConverter))] [ValueSerializer(typeof(KeyGestureValueSerializer))] public override InputGesture Gesture { get { return base.Gesture as KeyGesture; } set { if (value is KeyGesture) { base.Gesture = value; } else { throw new ArgumentException(SR.Get(SRID.InputBinding_ExpectedInputGesture, typeof(KeyGesture))); } } } ////// Modifier /// public ModifierKeys Modifiers { get { lock (_dataLock) { if (null != Gesture) { return ((KeyGesture)Gesture).Modifiers; } return ModifierKeys.None; } } set { lock (_dataLock) { if (null == Gesture) { Gesture = new KeyGesture(Key.None, (ModifierKeys)value, /*validateGesture = */ false); } else { Gesture = new KeyGesture(((KeyGesture)Gesture).Key, value, /*validateGesture = */ false); } } } } ////// Key /// public Key Key { get { lock (_dataLock) { if (null != Gesture) { return ((KeyGesture)Gesture).Key; } return Key.None; } } set { lock (_dataLock) { if (null == Gesture) { Gesture = new KeyGesture((Key)value, ModifierKeys.None, /*validateGesture = */ false); } else { Gesture = new KeyGesture(value, ((KeyGesture)Gesture).Modifiers, /*validateGesture = */ false); } } } } #endregion Public Methods //------------------------------------------------------ // // Private Fields // //------------------------------------------------------ } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ExpressionEditorSheet.cs
- PublisherMembershipCondition.cs
- DbProviderFactories.cs
- TerminatorSinks.cs
- Bitmap.cs
- IChannel.cs
- DataGridViewRowEventArgs.cs
- SingleAnimationUsingKeyFrames.cs
- SecurityContextSecurityToken.cs
- PageContentAsyncResult.cs
- ADMembershipProvider.cs
- BridgeDataReader.cs
- SetIndexBinder.cs
- AccessDataSourceDesigner.cs
- FormatVersion.cs
- EdmEntityTypeAttribute.cs
- QuaternionAnimation.cs
- TimeSpanValidatorAttribute.cs
- HttpHandler.cs
- SmiConnection.cs
- SynchronizedDispatch.cs
- SqlDataSourceTableQuery.cs
- SerializationInfo.cs
- XPSSignatureDefinition.cs
- Latin1Encoding.cs
- ReadOnlyMetadataCollection.cs
- SamlAction.cs
- AppSettings.cs
- UriScheme.cs
- TransformGroup.cs
- UITypeEditor.cs
- DirectionalAction.cs
- AnchoredBlock.cs
- ElementProxy.cs
- ExceptionUtil.cs
- CacheMemory.cs
- XmlUtil.cs
- DataGridViewCellErrorTextNeededEventArgs.cs
- Config.cs
- DataGridColumnFloatingHeader.cs
- BinaryWriter.cs
- XmlTextAttribute.cs
- MobileFormsAuthentication.cs
- ValueConversionAttribute.cs
- DataGridViewComboBoxColumn.cs
- SqlIdentifier.cs
- SecurityHelper.cs
- XmlValueConverter.cs
- StateDesigner.cs
- LocalizationParserHooks.cs
- BindingSource.cs
- WebHostUnsafeNativeMethods.cs
- TypedTableHandler.cs
- DataServiceQueryException.cs
- Token.cs
- BlobPersonalizationState.cs
- ThreadExceptionDialog.cs
- DataTableTypeConverter.cs
- ContentPlaceHolder.cs
- WindowsAuthenticationEventArgs.cs
- DynamicRenderer.cs
- DeploymentSection.cs
- RequestCacheManager.cs
- fixedPageContentExtractor.cs
- StatusBarAutomationPeer.cs
- ViewStateModeByIdAttribute.cs
- WinInetCache.cs
- XmlILIndex.cs
- PropertyDescriptor.cs
- OpenTypeLayout.cs
- MsmqIntegrationBindingElement.cs
- DocumentOutline.cs
- MsmqDiagnostics.cs
- RepeatInfo.cs
- FontResourceCache.cs
- DragEvent.cs
- RemoveStoryboard.cs
- TextRangeBase.cs
- Bold.cs
- EdmTypeAttribute.cs
- TabControl.cs
- FixedSOMSemanticBox.cs
- _MultipleConnectAsync.cs
- FolderLevelBuildProviderAppliesToAttribute.cs
- ObsoleteAttribute.cs
- DisplayMemberTemplateSelector.cs
- OpenFileDialog.cs
- ImageField.cs
- Literal.cs
- PropertyChangedEventManager.cs
- ScrollChrome.cs
- RootBuilder.cs
- BooleanToVisibilityConverter.cs
- CqlQuery.cs
- RegexWriter.cs
- AffineTransform3D.cs
- ExceptionDetail.cs
- XmlCharCheckingReader.cs
- ResXBuildProvider.cs
- FrameworkElementAutomationPeer.cs