ユーザーがカスタムグリッドの外側をクリックしたことを検出したいのですが、ユーザーがグリッドをクリックすると、常にLostFocusイベントを受け取ります。フォーカス可能は本当ですが、グリッドがフォーカスを取得することはないようです。誰か助けてくれませんか?
public class GridEditor : Grid
{
public GridEditor()
{
Loaded += GridEditor_Loaded;
}
private void GridEditor_Loaded(object sender, RoutedEventArgs e)
{
Focusable = true;
this.LostFocus += new RoutedEventHandler(GridEditor_LostFocus);
}
void GridEditor_LostFocus(object sender, RoutedEventArgs e)
{
if (!this.IsKeyboardFocusWithin && !this.IsMouseOver)
{
Commands.EditConfirmed.Execute(DataContext, this);
}
}