Hi,
On my ListBoxItem MouseEnter event I am creating a new window with the following code.
Window w = new Window();
w.Show();
When the mouse leaves the current item I want to close the window.
How do I do that?
Many Thanks.
Hi,
On my ListBoxItem MouseEnter event I am creating a new window with the following code.
Window w = new Window();
w.Show();
When the mouse leaves the current item I want to close the window.
How do I do that?
Many Thanks.
Store a reference to the window (w
in your case) in a place where both the event handler for MouseEnter and MouseExit can access it and then just do a w.Close()
.
Instead of storing the w in a local variable, store it in a member variable of the current class. On MouseExit, use the member variable to close the Window.
public partial class ListWindow
{
Window displayWindow;
public void OnListBoxItem_MouseEnter()
{
displayWindow = new Window();
displayWindow.Show();
}
public void OnListBoxItem_MouseExit()
{
displayWindow.Close();
}
}