Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Core / CSharp / System / Windows / Input / Keyboard.cs / 1305600 / Keyboard.cs
using System; using System.Windows; using MS.Win32; using System.Security; using System.Security.Permissions; namespace System.Windows.Input { ////// The Keyboard class represents the mouse device to the /// members of a context. /// ////// The static members of this class simply delegate to the primary /// keyboard device of the calling thread's input manager. /// public static class Keyboard { ////// PreviewKeyDown /// public static readonly RoutedEvent PreviewKeyDownEvent = EventManager.RegisterRoutedEvent("PreviewKeyDown", RoutingStrategy.Tunnel, typeof(KeyEventHandler), typeof(Keyboard)); ////// Adds a handler for the PreviewKeyDown attached event /// /// UIElement or ContentElement that listens to this event /// Event Handler to be added public static void AddPreviewKeyDownHandler(DependencyObject element, KeyEventHandler handler) { UIElement.AddHandler(element, PreviewKeyDownEvent, handler); } ////// Removes a handler for the PreviewKeyDown attached event /// /// UIElement or ContentElement that listens to this event /// Event Handler to be removed public static void RemovePreviewKeyDownHandler(DependencyObject element, KeyEventHandler handler) { UIElement.RemoveHandler(element, PreviewKeyDownEvent, handler); } ////// KeyDown /// public static readonly RoutedEvent KeyDownEvent = EventManager.RegisterRoutedEvent("KeyDown", RoutingStrategy.Bubble, typeof(KeyEventHandler), typeof(Keyboard)); ////// Adds a handler for the KeyDown attached event /// /// UIElement or ContentElement that listens to this event /// Event Handler to be added public static void AddKeyDownHandler(DependencyObject element, KeyEventHandler handler) { UIElement.AddHandler(element, KeyDownEvent, handler); } ////// Removes a handler for the KeyDown attached event /// /// UIElement or ContentElement that listens to this event /// Event Handler to be removed public static void RemoveKeyDownHandler(DependencyObject element, KeyEventHandler handler) { UIElement.RemoveHandler(element, KeyDownEvent, handler); } ////// PreviewKeyUp /// public static readonly RoutedEvent PreviewKeyUpEvent = EventManager.RegisterRoutedEvent("PreviewKeyUp", RoutingStrategy.Tunnel, typeof(KeyEventHandler), typeof(Keyboard)); ////// Adds a handler for the PreviewKeyUp attached event /// /// UIElement or ContentElement that listens to this event /// Event Handler to be added public static void AddPreviewKeyUpHandler(DependencyObject element, KeyEventHandler handler) { UIElement.AddHandler(element, PreviewKeyUpEvent, handler); } ////// Removes a handler for the PreviewKeyUp attached event /// /// UIElement or ContentElement that listens to this event /// Event Handler to be removed public static void RemovePreviewKeyUpHandler(DependencyObject element, KeyEventHandler handler) { UIElement.RemoveHandler(element, PreviewKeyUpEvent, handler); } ////// KeyUp /// public static readonly RoutedEvent KeyUpEvent = EventManager.RegisterRoutedEvent("KeyUp", RoutingStrategy.Bubble, typeof(KeyEventHandler), typeof(Keyboard)); ////// Adds a handler for the KeyUp attached event /// /// UIElement or ContentElement that listens to this event /// Event Handler to be added public static void AddKeyUpHandler(DependencyObject element, KeyEventHandler handler) { UIElement.AddHandler(element, KeyUpEvent, handler); } ////// Removes a handler for the KeyUp attached event /// /// UIElement or ContentElement that listens to this event /// Event Handler to be added public static void RemoveKeyUpHandler(DependencyObject element, KeyEventHandler handler) { UIElement.RemoveHandler(element, KeyUpEvent, handler); } ////// PreviewGotKeyboardFocus /// public static readonly RoutedEvent PreviewGotKeyboardFocusEvent = EventManager.RegisterRoutedEvent("PreviewGotKeyboardFocus", RoutingStrategy.Tunnel, typeof(KeyboardFocusChangedEventHandler), typeof(Keyboard)); ////// Adds a handler for the PreviewGotKeyboardFocus attached event /// /// UIElement or ContentElement that listens to this event /// Event Handler to be added public static void AddPreviewGotKeyboardFocusHandler(DependencyObject element, KeyboardFocusChangedEventHandler handler) { UIElement.AddHandler(element, PreviewGotKeyboardFocusEvent, handler); } ////// Removes a handler for the PreviewGotKeyboardFocus attached event /// /// UIElement or ContentElement that listens to this event /// Event Handler to be added public static void RemovePreviewGotKeyboardFocusHandler(DependencyObject element, KeyboardFocusChangedEventHandler handler) { UIElement.RemoveHandler(element, PreviewGotKeyboardFocusEvent, handler); } ////// PreviewKeyboardInputProviderAcquireFocus /// public static readonly RoutedEvent PreviewKeyboardInputProviderAcquireFocusEvent = EventManager.RegisterRoutedEvent("PreviewKeyboardInputProviderAcquireFocus", RoutingStrategy.Tunnel, typeof(KeyboardInputProviderAcquireFocusEventHandler), typeof(Keyboard)); ////// Adds a handler for the PreviewKeyboardInputProviderAcquireFocus attached event /// /// UIElement or ContentElement that listens to this event /// Event Handler to be added public static void AddPreviewKeyboardInputProviderAcquireFocusHandler(DependencyObject element, KeyboardInputProviderAcquireFocusEventHandler handler) { UIElement.AddHandler(element, PreviewKeyboardInputProviderAcquireFocusEvent, handler); } ////// Removes a handler for the PreviewKeyboardInputProviderAcquireFocus attached event /// /// UIElement or ContentElement that listens to this event /// Event Handler to be removed public static void RemovePreviewKeyboardInputProviderAcquireFocusHandler(DependencyObject element, KeyboardInputProviderAcquireFocusEventHandler handler) { UIElement.RemoveHandler(element, PreviewKeyboardInputProviderAcquireFocusEvent, handler); } ////// KeyboardInputProviderAcquireFocus /// public static readonly RoutedEvent KeyboardInputProviderAcquireFocusEvent = EventManager.RegisterRoutedEvent("KeyboardInputProviderAcquireFocus", RoutingStrategy.Bubble, typeof(KeyboardInputProviderAcquireFocusEventHandler), typeof(Keyboard)); ////// Adds a handler for the KeyboardInputProviderAcquireFocus attached event /// /// UIElement or ContentElement that listens to this event /// Event Handler to be added public static void AddKeyboardInputProviderAcquireFocusHandler(DependencyObject element, KeyboardInputProviderAcquireFocusEventHandler handler) { UIElement.AddHandler(element, KeyboardInputProviderAcquireFocusEvent, handler); } ////// Removes a handler for the KeyboardInputProviderAcquireFocus attached event /// /// UIElement or ContentElement that listens to this event /// Event Handler to be removed public static void RemoveKeyboardInputProviderAcquireFocusHandler(DependencyObject element, KeyboardInputProviderAcquireFocusEventHandler handler) { UIElement.RemoveHandler(element, KeyboardInputProviderAcquireFocusEvent, handler); } ////// GotKeyboardFocus /// public static readonly RoutedEvent GotKeyboardFocusEvent = EventManager.RegisterRoutedEvent("GotKeyboardFocus", RoutingStrategy.Bubble, typeof(KeyboardFocusChangedEventHandler), typeof(Keyboard)); ////// Adds a handler for the GotKeyboardFocus attached event /// /// UIElement or ContentElement that listens to this event /// Event Handler to be added public static void AddGotKeyboardFocusHandler(DependencyObject element, KeyboardFocusChangedEventHandler handler) { UIElement.AddHandler(element, GotKeyboardFocusEvent, handler); } ////// Removes a handler for the GotKeyboardFocus attached event /// /// UIElement or ContentElement that listens to this event /// Event Handler to be removed public static void RemoveGotKeyboardFocusHandler(DependencyObject element, KeyboardFocusChangedEventHandler handler) { UIElement.RemoveHandler(element, GotKeyboardFocusEvent, handler); } ////// PreviewLostKeyboardFocus /// public static readonly RoutedEvent PreviewLostKeyboardFocusEvent = EventManager.RegisterRoutedEvent("PreviewLostKeyboardFocus", RoutingStrategy.Tunnel, typeof(KeyboardFocusChangedEventHandler), typeof(Keyboard)); ////// Adds a handler for the PreviewLostKeyboardFocus attached event /// /// UIElement or ContentElement that listens to this event /// Event Handler to be added public static void AddPreviewLostKeyboardFocusHandler(DependencyObject element, KeyboardFocusChangedEventHandler handler) { UIElement.AddHandler(element, PreviewLostKeyboardFocusEvent, handler); } ////// Removes a handler for the PreviewLostKeyboardFocus attached event /// /// UIElement or ContentElement that listens to this event /// Event Handler to be removed public static void RemovePreviewLostKeyboardFocusHandler(DependencyObject element, KeyboardFocusChangedEventHandler handler) { UIElement.RemoveHandler(element, PreviewLostKeyboardFocusEvent, handler); } ////// LostKeyboardFocus /// public static readonly RoutedEvent LostKeyboardFocusEvent = EventManager.RegisterRoutedEvent("LostKeyboardFocus", RoutingStrategy.Bubble, typeof(KeyboardFocusChangedEventHandler), typeof(Keyboard)); ////// Adds a handler for the LostKeyboardFocus attached event /// /// UIElement or ContentElement that listens to this event /// Event Handler to be added public static void AddLostKeyboardFocusHandler(DependencyObject element, KeyboardFocusChangedEventHandler handler) { UIElement.AddHandler(element, LostKeyboardFocusEvent, handler); } ////// Removes a handler for the LostKeyboardFocus attached event /// /// UIElement or ContentElement that removedto this event /// Event Handler to be removed public static void RemoveLostKeyboardFocusHandler(DependencyObject element, KeyboardFocusChangedEventHandler handler) { UIElement.RemoveHandler(element, LostKeyboardFocusEvent, handler); } ////// Returns the element that the keyboard is focused on. /// public static IInputElement FocusedElement { get { return Keyboard.PrimaryDevice.FocusedElement; } } ////// Clears focus. /// public static void ClearFocus() { Keyboard.PrimaryDevice.ClearFocus(); } ////// Focuses the keyboard on a particular element. /// /// /// The element to focus the keyboard on. /// public static IInputElement Focus(IInputElement element) { return Keyboard.PrimaryDevice.Focus(element); } ////// The default mode for restoring focus. /// public static RestoreFocusMode DefaultRestoreFocusMode { get { return Keyboard.PrimaryDevice.DefaultRestoreFocusMode; } set { Keyboard.PrimaryDevice.DefaultRestoreFocusMode = value; } } /// /// The set of modifier keys currently pressed. /// public static ModifierKeys Modifiers { get { return Keyboard.PrimaryDevice.Modifiers; } } ////// Returns whether or not the specified key is down. /// public static bool IsKeyDown(Key key) { return Keyboard.PrimaryDevice.IsKeyDown(key); } ////// Returns whether or not the specified key is up. /// public static bool IsKeyUp(Key key) { return Keyboard.PrimaryDevice.IsKeyUp(key); } ////// Returns whether or not the specified key is toggled. /// public static bool IsKeyToggled(Key key) { return Keyboard.PrimaryDevice.IsKeyToggled(key); } ////// Returns the state of the specified key. /// public static KeyStates GetKeyStates(Key key) { return Keyboard.PrimaryDevice.GetKeyStates(key); } ////// The primary keyboard device. /// ////// Critical: This code accesses the InputManager which causes an elevation /// PublicOK: It is ok to return the primary device /// public static KeyboardDevice PrimaryDevice { [SecurityCritical] get { KeyboardDevice keyboardDevice = InputManager.UnsecureCurrent.PrimaryKeyboardDevice; return keyboardDevice; } } // Check for Valid enum, as any int can be casted to the enum. internal static bool IsValidKey(Key key) { return ((int)key >= (int)Key.None && (int)key <= (int)Key.OemClear); } ////// Critical: This code accesses critical data(_activeSource) /// TreatAsSafe: Although it accesses critical data it does not modify or expose it, only compares against it. /// [SecurityCritical, SecurityTreatAsSafe] internal static bool IsFocusable(DependencyObject element) { // CODE if(element == null) { return false; } UIElement uie = element as UIElement; if(uie != null) { if(uie.IsVisible == false) { return false; } } if((bool)element.GetValue(UIElement.IsEnabledProperty) == false) { return false; } // CODE bool hasModifiers = false; BaseValueSourceInternal valueSource = element.GetValueSource(UIElement.FocusableProperty, null, out hasModifiers); bool focusable = (bool) element.GetValue(UIElement.FocusableProperty); if(!focusable && valueSource == BaseValueSourceInternal.Default && !hasModifiers) { // The Focusable property was not explicitly set to anything. // The default value is generally false, but true in a few cases. if(FocusManager.GetIsFocusScope(element)) { // Focus scopes are considered focusable, even if // the Focusable property is false. return true; } else if(uie != null && uie.InternalVisualParent == null) { PresentationSource presentationSource = PresentationSource.CriticalFromVisual(uie); if(presentationSource != null) { // A UIElements that is the root of a PresentationSource is considered focusable. return true; } } } return focusable; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. using System; using System.Windows; using MS.Win32; using System.Security; using System.Security.Permissions; namespace System.Windows.Input { ////// The Keyboard class represents the mouse device to the /// members of a context. /// ////// The static members of this class simply delegate to the primary /// keyboard device of the calling thread's input manager. /// public static class Keyboard { ////// PreviewKeyDown /// public static readonly RoutedEvent PreviewKeyDownEvent = EventManager.RegisterRoutedEvent("PreviewKeyDown", RoutingStrategy.Tunnel, typeof(KeyEventHandler), typeof(Keyboard)); ////// Adds a handler for the PreviewKeyDown attached event /// /// UIElement or ContentElement that listens to this event /// Event Handler to be added public static void AddPreviewKeyDownHandler(DependencyObject element, KeyEventHandler handler) { UIElement.AddHandler(element, PreviewKeyDownEvent, handler); } ////// Removes a handler for the PreviewKeyDown attached event /// /// UIElement or ContentElement that listens to this event /// Event Handler to be removed public static void RemovePreviewKeyDownHandler(DependencyObject element, KeyEventHandler handler) { UIElement.RemoveHandler(element, PreviewKeyDownEvent, handler); } ////// KeyDown /// public static readonly RoutedEvent KeyDownEvent = EventManager.RegisterRoutedEvent("KeyDown", RoutingStrategy.Bubble, typeof(KeyEventHandler), typeof(Keyboard)); ////// Adds a handler for the KeyDown attached event /// /// UIElement or ContentElement that listens to this event /// Event Handler to be added public static void AddKeyDownHandler(DependencyObject element, KeyEventHandler handler) { UIElement.AddHandler(element, KeyDownEvent, handler); } ////// Removes a handler for the KeyDown attached event /// /// UIElement or ContentElement that listens to this event /// Event Handler to be removed public static void RemoveKeyDownHandler(DependencyObject element, KeyEventHandler handler) { UIElement.RemoveHandler(element, KeyDownEvent, handler); } ////// PreviewKeyUp /// public static readonly RoutedEvent PreviewKeyUpEvent = EventManager.RegisterRoutedEvent("PreviewKeyUp", RoutingStrategy.Tunnel, typeof(KeyEventHandler), typeof(Keyboard)); ////// Adds a handler for the PreviewKeyUp attached event /// /// UIElement or ContentElement that listens to this event /// Event Handler to be added public static void AddPreviewKeyUpHandler(DependencyObject element, KeyEventHandler handler) { UIElement.AddHandler(element, PreviewKeyUpEvent, handler); } ////// Removes a handler for the PreviewKeyUp attached event /// /// UIElement or ContentElement that listens to this event /// Event Handler to be removed public static void RemovePreviewKeyUpHandler(DependencyObject element, KeyEventHandler handler) { UIElement.RemoveHandler(element, PreviewKeyUpEvent, handler); } ////// KeyUp /// public static readonly RoutedEvent KeyUpEvent = EventManager.RegisterRoutedEvent("KeyUp", RoutingStrategy.Bubble, typeof(KeyEventHandler), typeof(Keyboard)); ////// Adds a handler for the KeyUp attached event /// /// UIElement or ContentElement that listens to this event /// Event Handler to be added public static void AddKeyUpHandler(DependencyObject element, KeyEventHandler handler) { UIElement.AddHandler(element, KeyUpEvent, handler); } ////// Removes a handler for the KeyUp attached event /// /// UIElement or ContentElement that listens to this event /// Event Handler to be added public static void RemoveKeyUpHandler(DependencyObject element, KeyEventHandler handler) { UIElement.RemoveHandler(element, KeyUpEvent, handler); } ////// PreviewGotKeyboardFocus /// public static readonly RoutedEvent PreviewGotKeyboardFocusEvent = EventManager.RegisterRoutedEvent("PreviewGotKeyboardFocus", RoutingStrategy.Tunnel, typeof(KeyboardFocusChangedEventHandler), typeof(Keyboard)); ////// Adds a handler for the PreviewGotKeyboardFocus attached event /// /// UIElement or ContentElement that listens to this event /// Event Handler to be added public static void AddPreviewGotKeyboardFocusHandler(DependencyObject element, KeyboardFocusChangedEventHandler handler) { UIElement.AddHandler(element, PreviewGotKeyboardFocusEvent, handler); } ////// Removes a handler for the PreviewGotKeyboardFocus attached event /// /// UIElement or ContentElement that listens to this event /// Event Handler to be added public static void RemovePreviewGotKeyboardFocusHandler(DependencyObject element, KeyboardFocusChangedEventHandler handler) { UIElement.RemoveHandler(element, PreviewGotKeyboardFocusEvent, handler); } ////// PreviewKeyboardInputProviderAcquireFocus /// public static readonly RoutedEvent PreviewKeyboardInputProviderAcquireFocusEvent = EventManager.RegisterRoutedEvent("PreviewKeyboardInputProviderAcquireFocus", RoutingStrategy.Tunnel, typeof(KeyboardInputProviderAcquireFocusEventHandler), typeof(Keyboard)); ////// Adds a handler for the PreviewKeyboardInputProviderAcquireFocus attached event /// /// UIElement or ContentElement that listens to this event /// Event Handler to be added public static void AddPreviewKeyboardInputProviderAcquireFocusHandler(DependencyObject element, KeyboardInputProviderAcquireFocusEventHandler handler) { UIElement.AddHandler(element, PreviewKeyboardInputProviderAcquireFocusEvent, handler); } ////// Removes a handler for the PreviewKeyboardInputProviderAcquireFocus attached event /// /// UIElement or ContentElement that listens to this event /// Event Handler to be removed public static void RemovePreviewKeyboardInputProviderAcquireFocusHandler(DependencyObject element, KeyboardInputProviderAcquireFocusEventHandler handler) { UIElement.RemoveHandler(element, PreviewKeyboardInputProviderAcquireFocusEvent, handler); } ////// KeyboardInputProviderAcquireFocus /// public static readonly RoutedEvent KeyboardInputProviderAcquireFocusEvent = EventManager.RegisterRoutedEvent("KeyboardInputProviderAcquireFocus", RoutingStrategy.Bubble, typeof(KeyboardInputProviderAcquireFocusEventHandler), typeof(Keyboard)); ////// Adds a handler for the KeyboardInputProviderAcquireFocus attached event /// /// UIElement or ContentElement that listens to this event /// Event Handler to be added public static void AddKeyboardInputProviderAcquireFocusHandler(DependencyObject element, KeyboardInputProviderAcquireFocusEventHandler handler) { UIElement.AddHandler(element, KeyboardInputProviderAcquireFocusEvent, handler); } ////// Removes a handler for the KeyboardInputProviderAcquireFocus attached event /// /// UIElement or ContentElement that listens to this event /// Event Handler to be removed public static void RemoveKeyboardInputProviderAcquireFocusHandler(DependencyObject element, KeyboardInputProviderAcquireFocusEventHandler handler) { UIElement.RemoveHandler(element, KeyboardInputProviderAcquireFocusEvent, handler); } ////// GotKeyboardFocus /// public static readonly RoutedEvent GotKeyboardFocusEvent = EventManager.RegisterRoutedEvent("GotKeyboardFocus", RoutingStrategy.Bubble, typeof(KeyboardFocusChangedEventHandler), typeof(Keyboard)); ////// Adds a handler for the GotKeyboardFocus attached event /// /// UIElement or ContentElement that listens to this event /// Event Handler to be added public static void AddGotKeyboardFocusHandler(DependencyObject element, KeyboardFocusChangedEventHandler handler) { UIElement.AddHandler(element, GotKeyboardFocusEvent, handler); } ////// Removes a handler for the GotKeyboardFocus attached event /// /// UIElement or ContentElement that listens to this event /// Event Handler to be removed public static void RemoveGotKeyboardFocusHandler(DependencyObject element, KeyboardFocusChangedEventHandler handler) { UIElement.RemoveHandler(element, GotKeyboardFocusEvent, handler); } ////// PreviewLostKeyboardFocus /// public static readonly RoutedEvent PreviewLostKeyboardFocusEvent = EventManager.RegisterRoutedEvent("PreviewLostKeyboardFocus", RoutingStrategy.Tunnel, typeof(KeyboardFocusChangedEventHandler), typeof(Keyboard)); ////// Adds a handler for the PreviewLostKeyboardFocus attached event /// /// UIElement or ContentElement that listens to this event /// Event Handler to be added public static void AddPreviewLostKeyboardFocusHandler(DependencyObject element, KeyboardFocusChangedEventHandler handler) { UIElement.AddHandler(element, PreviewLostKeyboardFocusEvent, handler); } ////// Removes a handler for the PreviewLostKeyboardFocus attached event /// /// UIElement or ContentElement that listens to this event /// Event Handler to be removed public static void RemovePreviewLostKeyboardFocusHandler(DependencyObject element, KeyboardFocusChangedEventHandler handler) { UIElement.RemoveHandler(element, PreviewLostKeyboardFocusEvent, handler); } ////// LostKeyboardFocus /// public static readonly RoutedEvent LostKeyboardFocusEvent = EventManager.RegisterRoutedEvent("LostKeyboardFocus", RoutingStrategy.Bubble, typeof(KeyboardFocusChangedEventHandler), typeof(Keyboard)); ////// Adds a handler for the LostKeyboardFocus attached event /// /// UIElement or ContentElement that listens to this event /// Event Handler to be added public static void AddLostKeyboardFocusHandler(DependencyObject element, KeyboardFocusChangedEventHandler handler) { UIElement.AddHandler(element, LostKeyboardFocusEvent, handler); } ////// Removes a handler for the LostKeyboardFocus attached event /// /// UIElement or ContentElement that removedto this event /// Event Handler to be removed public static void RemoveLostKeyboardFocusHandler(DependencyObject element, KeyboardFocusChangedEventHandler handler) { UIElement.RemoveHandler(element, LostKeyboardFocusEvent, handler); } ////// Returns the element that the keyboard is focused on. /// public static IInputElement FocusedElement { get { return Keyboard.PrimaryDevice.FocusedElement; } } ////// Clears focus. /// public static void ClearFocus() { Keyboard.PrimaryDevice.ClearFocus(); } ////// Focuses the keyboard on a particular element. /// /// /// The element to focus the keyboard on. /// public static IInputElement Focus(IInputElement element) { return Keyboard.PrimaryDevice.Focus(element); } ////// The default mode for restoring focus. /// public static RestoreFocusMode DefaultRestoreFocusMode { get { return Keyboard.PrimaryDevice.DefaultRestoreFocusMode; } set { Keyboard.PrimaryDevice.DefaultRestoreFocusMode = value; } } /// /// The set of modifier keys currently pressed. /// public static ModifierKeys Modifiers { get { return Keyboard.PrimaryDevice.Modifiers; } } ////// Returns whether or not the specified key is down. /// public static bool IsKeyDown(Key key) { return Keyboard.PrimaryDevice.IsKeyDown(key); } ////// Returns whether or not the specified key is up. /// public static bool IsKeyUp(Key key) { return Keyboard.PrimaryDevice.IsKeyUp(key); } ////// Returns whether or not the specified key is toggled. /// public static bool IsKeyToggled(Key key) { return Keyboard.PrimaryDevice.IsKeyToggled(key); } ////// Returns the state of the specified key. /// public static KeyStates GetKeyStates(Key key) { return Keyboard.PrimaryDevice.GetKeyStates(key); } ////// The primary keyboard device. /// ////// Critical: This code accesses the InputManager which causes an elevation /// PublicOK: It is ok to return the primary device /// public static KeyboardDevice PrimaryDevice { [SecurityCritical] get { KeyboardDevice keyboardDevice = InputManager.UnsecureCurrent.PrimaryKeyboardDevice; return keyboardDevice; } } // Check for Valid enum, as any int can be casted to the enum. internal static bool IsValidKey(Key key) { return ((int)key >= (int)Key.None && (int)key <= (int)Key.OemClear); } ////// Critical: This code accesses critical data(_activeSource) /// TreatAsSafe: Although it accesses critical data it does not modify or expose it, only compares against it. /// [SecurityCritical, SecurityTreatAsSafe] internal static bool IsFocusable(DependencyObject element) { // CODE if(element == null) { return false; } UIElement uie = element as UIElement; if(uie != null) { if(uie.IsVisible == false) { return false; } } if((bool)element.GetValue(UIElement.IsEnabledProperty) == false) { return false; } // CODE bool hasModifiers = false; BaseValueSourceInternal valueSource = element.GetValueSource(UIElement.FocusableProperty, null, out hasModifiers); bool focusable = (bool) element.GetValue(UIElement.FocusableProperty); if(!focusable && valueSource == BaseValueSourceInternal.Default && !hasModifiers) { // The Focusable property was not explicitly set to anything. // The default value is generally false, but true in a few cases. if(FocusManager.GetIsFocusScope(element)) { // Focus scopes are considered focusable, even if // the Focusable property is false. return true; } else if(uie != null && uie.InternalVisualParent == null) { PresentationSource presentationSource = PresentationSource.CriticalFromVisual(uie); if(presentationSource != null) { // A UIElements that is the root of a PresentationSource is considered focusable. return true; } } } return focusable; } } } // 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
- CompositeFontInfo.cs
- XmlSchemaInclude.cs
- WebColorConverter.cs
- mediaeventshelper.cs
- HtmlSelect.cs
- ObjectListItemCollection.cs
- HMACSHA512.cs
- ConfigurationStrings.cs
- SQLInt32Storage.cs
- ToolStripTextBox.cs
- HeaderedContentControl.cs
- OracleLob.cs
- StyleBamlTreeBuilder.cs
- RuleRefElement.cs
- ComponentDispatcherThread.cs
- ProfileService.cs
- CmsInterop.cs
- CurrentTimeZone.cs
- DeploymentSection.cs
- UrlMappingsModule.cs
- TransactedReceiveData.cs
- HttpHeaderCollection.cs
- ControlEvent.cs
- RegexCompiler.cs
- UnhandledExceptionEventArgs.cs
- Point3D.cs
- MSHTMLHost.cs
- SafeNativeMethodsMilCoreApi.cs
- Thickness.cs
- MethodBody.cs
- Vector3D.cs
- DatagridviewDisplayedBandsData.cs
- CodeTypeReferenceExpression.cs
- ProjectionCamera.cs
- PackagePartCollection.cs
- TlsSspiNegotiation.cs
- VisualStyleTypesAndProperties.cs
- TransformConverter.cs
- ObjectDataSourceSelectingEventArgs.cs
- NativeMethods.cs
- DataGridViewColumnConverter.cs
- wgx_sdk_version.cs
- WebPartDisplayMode.cs
- RegisteredHiddenField.cs
- MetaTable.cs
- ComponentResourceKey.cs
- Perspective.cs
- DataGridViewTopRowAccessibleObject.cs
- X509ChainElement.cs
- StylusPointCollection.cs
- FixedTextBuilder.cs
- HttpInputStream.cs
- COSERVERINFO.cs
- ByteStack.cs
- LeaseManager.cs
- TemplatePropertyEntry.cs
- XmlRootAttribute.cs
- UInt16.cs
- OrCondition.cs
- XmlNodeList.cs
- CommandHelpers.cs
- RunClient.cs
- FloatUtil.cs
- ReadOnlyObservableCollection.cs
- Utils.cs
- PreloadedPackages.cs
- CharEntityEncoderFallback.cs
- MsmqOutputSessionChannel.cs
- EncoderBestFitFallback.cs
- ThicknessKeyFrameCollection.cs
- InstanceCreationEditor.cs
- Visual3D.cs
- EdmSchemaAttribute.cs
- MulticastNotSupportedException.cs
- Component.cs
- Int64Animation.cs
- ISessionStateStore.cs
- RegionData.cs
- FormViewUpdatedEventArgs.cs
- SourceChangedEventArgs.cs
- DecimalStorage.cs
- DataRowComparer.cs
- ServiceNameCollection.cs
- DataFormats.cs
- SqlClientWrapperSmiStream.cs
- SQLStringStorage.cs
- TextAction.cs
- TabItem.cs
- ListViewDesigner.cs
- NavigationFailedEventArgs.cs
- FormatVersion.cs
- Config.cs
- PingReply.cs
- UnsafeNativeMethods.cs
- SqlColumnizer.cs
- PropertyGeneratedEventArgs.cs
- DockAndAnchorLayout.cs
- AbsoluteQuery.cs
- EventProviderTraceListener.cs
- ButtonBase.cs