In my program I first open the main window. In this window I open some other windows, by clicking a button. While testing my program I discovered two problems. First: If I open a window and close it, it's impossible for me to reopen it. Visual Studio then shows an error message in the codeline Window.Show():
InvalidOperationException was unhandled. Visibility can not set or Show, or ShowDialog WindowInteropHelper.EnsureHandle can not be called after a window has been closed.
The whole code for opening the window, looks like this:
private void CmdDistance_Click(object senderr, RoutedEventArgs e)
{
distance.Show();
}
It's nearly the same code for opening the other two windows, but I use other buttons. The problem also happens with the other two windows.
The second problem is that, if I first open the Window distance and close it, by clicking the x, and open a other window, the second window indeed opens, but the functions inside the window aren't executed. Currently I use the same code in every window, just for testing but it just works in the first opened window. Still here I don't know what I did wrong. I post here the code I use to calle the function inside the individual windows.
private void MousePosition(object sender, System.Windows.Input.MouseEventArgs e)
{
if (distance!=null && distance.Visibility==Visibility.Visible )
{
if (e.LeftButton == MouseButtonState.Pressed)
{
myMousePosition = e.GetPosition(DepthImage);
depthWidth = mySensor.DepthStream.FrameWidth;
distance.setDistancePosition(myMousePosition, depthWidth, mySkeletonArray);
}
}
else if (rectangle_area != null && rectangle_area.Visibility == Visibility.Visible)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
myMousePosition = e.GetPosition(DepthImage);
depthWidth = mySensor.DepthStream.FrameWidth;
rectangle_area.setRectanglePosition(myMousePosition, depthWidth, mySkeletonArray);
}
}
else if (circle_area != null && circle_area.Visibility == Visibility.Visible)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
myMousePosition = e.GetPosition(DepthImage);
depthWidth = mySensor.DepthStream.FrameWidth;
circle_area.setCirclePosition(myMousePosition, depthWidth, mySkeletonArray);
}
}
}
I don't know if the problems work together so I thought I just post both in the same question and hope someone sees what I did wrong.