Created
June 23, 2011 15:08
-
-
Save davidalpert/1042709 to your computer and use it in GitHub Desktop.
Abstracting WPF's KeyEventArgs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Extracts the interesting parts of a <see cref="KeyEventArgs"/> so that we can mock it outside of the WPF runtime in a test. | |
/// </summary> | |
public interface IKeyEventArgs | |
{ | |
bool Handled { get; set; } | |
object OriginalSource { get; } | |
Key DeadCharProcessedKey { get; } | |
Key ImeProcessedKey { get; } | |
bool IsDown { get; } | |
bool IsRepeat { get; } | |
bool IsToggled { get; } | |
bool IsUp { get; } | |
Key Key { get; } | |
KeyStates KeyStates { get; } | |
Key SystemKey { get; } | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Wraps the interesting parts of a <see cref="KeyEventArgs"/> so that we can instantiate it outside of the WPF runtime in a test. | |
/// </summary> | |
public class KeyEventArgsWrapper : IKeyEventArgs | |
{ | |
KeyEventArgs e; | |
public KeyEventArgsWrapper(KeyEventArgs e) | |
{ | |
this.e = e; | |
} | |
public bool Handled | |
{ | |
get { return e.Handled; } | |
set { e.Handled = value; } | |
} | |
public object OriginalSource { get { return e.OriginalSource; } } | |
public Key DeadCharProcessedKey { get { return e.DeadCharProcessedKey; } } | |
public Key ImeProcessedKey { get { return e.ImeProcessedKey; } } | |
public bool IsDown { get { return e.IsDown; } } | |
public bool IsRepeat { get { return e.IsRepeat; } } | |
public bool IsToggled { get { return e.IsToggled; } } | |
public bool IsUp { get { return e.IsUp; } } | |
public Key Key { get { return e.Key; } } | |
public KeyStates KeyStates { get { return e.KeyStates; } } | |
public Key SystemKey { get { return e.SystemKey; } } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment