Чтобы получить выбор Passwordbox, я использую этот код:
private Selection GetSelection(PasswordBox pb)
{
Selection result = new Selection();
PropertyInfo infos = pb.GetType().GetProperty("Selection", BindingFlags.NonPublic | BindingFlags.Instance);
object selection = infos.GetValue(pb, null);
IEnumerable _textSegments = (IEnumerable)selection.GetType().BaseType.GetField("_textSegments", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(selection);
object first_textSegments = _textSegments.Cast<object>().FirstOrDefault();
object start = first_textSegments.GetType().GetProperty("Start", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(first_textSegments, null);
result.start = (int) start.GetType().GetProperty("Offset", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(start, null);
object end = first_textSegments.GetType().GetProperty("End", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(first_textSegments, null);
result.length = (int)start.GetType().GetProperty("Offset", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(end, null) - result.start;
return result;
}
struct Selection
{
public int start;
public int length;
}
Протестировано на .net 4.0, надеюсь, что это работает и для вас.