I'm building a user control that includes a flyout panel.
When I click the button to open the panel I'm trying to capture the mouse so that I can detect if the user clicks off the flyout panel so I can close it.
But right after I capture the mouse, I get a lost mousecapture event and I can't detect the clicks outside of the panel.
here is where I detect the straight open close click
private void Grid_MouseUP(object sender, MouseButtonEventArgs e)
{
if (indicatorVM != null)
{
if (indicatorVM.SettingsFlyoutVisibility == Visibility.Collapsed)
{
doRelease = false;
indicatorVM.SettingsFlyoutVisibility = Visibility.Visible;
bool result = this.CaptureMouse();
result = Mouse.Capture(this, CaptureMode.SubTree);
}
else
{
doRelease = true;
indicatorVM.SettingsFlyoutVisibility = Visibility.Collapsed;
this.ReleaseMouseCapture();
}
}
}
If I wire into the capture lost event, it's hit immediately after the flyout opens. When I check the result variable, regardless of how I capture the mouse, the result is true, so it appears to be working correctly.
Any ideas?