Created
October 12, 2017 21:36
-
-
Save punker76/ed9fafcdb56da179f255db52f3787052 to your computer and use it in GitHub Desktop.
GetPasswordBoxCaretPostion
This file contains 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
private int GetPasswordBoxCaretPostion(PasswordBox passwordBox) | |
{ | |
var infos = passwordBox?.GetType()?.GetProperty("Selection", BindingFlags.NonPublic | BindingFlags.Instance); | |
var selection = infos?.GetValue(passwordBox, null) as TextSelection; | |
var tTextRange = selection?.GetType()?.GetInterfaces()?.Where(x => x.Name == "ITextRange")?.FirstOrDefault(); | |
var oStart = tTextRange?.GetProperty("Start")?.GetGetMethod()?.Invoke(selection, null); | |
var value = oStart?.GetType()?.GetProperty("Offset", BindingFlags.NonPublic | BindingFlags.Instance)?.GetValue(oStart, null) as int?; | |
var caretPosition = value.GetValueOrDefault(0); | |
return caretPosition; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment