我想检测用户何时在自定义网格之外单击,但是当用户单击网格时,我总是会收到 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);
}
}