Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / 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
- TranslateTransform.cs
- ChannelBinding.cs
- EventLogPermissionAttribute.cs
- MemberDescriptor.cs
- PropertyMapper.cs
- AssemblyBuilderData.cs
- SystemIcmpV4Statistics.cs
- UrlParameterReader.cs
- sqlinternaltransaction.cs
- XomlSerializationHelpers.cs
- ProcessModuleCollection.cs
- TypeExtensionConverter.cs
- HMAC.cs
- TextContainer.cs
- TableRow.cs
- Native.cs
- SafeProcessHandle.cs
- RenderingEventArgs.cs
- ConnectorRouter.cs
- SettingsPropertyValue.cs
- StringSorter.cs
- Timer.cs
- SqlVersion.cs
- WebControlParameterProxy.cs
- HtmlToClrEventProxy.cs
- AtomServiceDocumentSerializer.cs
- ChameleonKey.cs
- UrlPath.cs
- XmlObjectSerializerReadContextComplexJson.cs
- Pair.cs
- ScrollBarAutomationPeer.cs
- X509SubjectKeyIdentifierClause.cs
- XmlEncodedRawTextWriter.cs
- XmlFormatExtensionAttribute.cs
- HTMLTextWriter.cs
- TextLine.cs
- HtmlEmptyTagControlBuilder.cs
- OracleString.cs
- InputLanguageCollection.cs
- AnnotationHelper.cs
- DataGridViewColumnEventArgs.cs
- SimpleNameService.cs
- ToolboxBitmapAttribute.cs
- CharacterBufferReference.cs
- StyleXamlParser.cs
- SpecularMaterial.cs
- UIAgentAsyncEndRequest.cs
- VariantWrapper.cs
- SiteMapNodeItem.cs
- KnownTypeDataContractResolver.cs
- MetadataUtilsSmi.cs
- TreeNodeSelectionProcessor.cs
- EventHandlerList.cs
- ToolStripDropDownClosedEventArgs.cs
- TableItemStyle.cs
- SizeKeyFrameCollection.cs
- ButtonField.cs
- SingleAnimationBase.cs
- ResourceAssociationTypeEnd.cs
- RtfToken.cs
- EntitySqlQueryBuilder.cs
- ValidationRule.cs
- ConfigurationErrorsException.cs
- StreamReader.cs
- InProcStateClientManager.cs
- SystemUdpStatistics.cs
- HttpCachePolicyElement.cs
- SimplePropertyEntry.cs
- SystemUdpStatistics.cs
- PathFigureCollectionConverter.cs
- basemetadatamappingvisitor.cs
- ToolStripItemGlyph.cs
- ForEachAction.cs
- ContextMenuAutomationPeer.cs
- TreeNode.cs
- ServiceDebugBehavior.cs
- TextCollapsingProperties.cs
- TypedAsyncResult.cs
- IgnoreDeviceFilterElementCollection.cs
- Run.cs
- PrimitiveType.cs
- DurableInstanceManager.cs
- WindowsGraphics.cs
- IsolationInterop.cs
- ReadWriteSpinLock.cs
- JoinCqlBlock.cs
- SerialPinChanges.cs
- PolygonHotSpot.cs
- GridViewItemAutomationPeer.cs
- XmlCustomFormatter.cs
- COSERVERINFO.cs
- TemplateInstanceAttribute.cs
- NumericExpr.cs
- ImageInfo.cs
- ObjectToModelValueConverter.cs
- BitmapEffect.cs
- RepeaterCommandEventArgs.cs
- TemplateBindingExtension.cs
- DataGridBoolColumn.cs
- ProgressBarBrushConverter.cs