各コンポーネントの LostFocus イベントを使用せずに、ac# 形式でフォーカスを失ったユーザーを取得する方法はありますか?
[編集]
オンスクリーン キーボードが必要です。
キープレスを起動するために最後にフォーカスされたコントロールを保存する必要がありますが、ウィンドウ内のすべてに対してそれを行う必要があります。
また、主なプロジェクトはwpfです.itemsTemplateなどとしてネストされたコンポーネントがあるよりも...
私は最終的にこれを使用しました:
foreach (Control uie in FindInLogicalTreeDown(this, typeof(TextBox))) AssignEvents(uie);
private static IEnumerable<DependencyObject> FindInLogicalTreeDown(DependencyObject obj, Type type)
{
if (obj != null)
{
if (obj.GetType() == type) { yield return obj; }
foreach (object child in LogicalTreeHelper.GetChildren(obj))
if (typeof(DependencyObject).IsAssignableFrom(child.GetType()))
foreach (var nobj in FindInLogicalTreeDown((DependencyObject)child, type)) yield return nobj;
}
yield break;
}
void AssignEvents(Control element)
{
element.GotMouseCapture += new MouseEventHandler(Component_GotFocus);
}
public Control LastFocus { get; set; }
public void Component_GotFocus(object sender, RoutedEventArgs e)
{
LastFocus = (Control)sender;
if (LastFocus.GetType() == typeof(TextBox)) { KeyboardVisible = true; }
}
イベントをサブスクライブし、最後に発生したフォーカスを失ったイベントを追跡しない限り、方法はないと思います