I want to display the button only when the user hovers the mouse at its location, as soon as the mouse leaves the area, the button should return to hide. Here is my button code.
<StackPanel Name="ButtonOptions" Orientation="Horizontal" DockPanel.Dock="Bottom" Background="DarkBlue" Height="50" Width="auto"> <Button Name="LoginButton" FontSize="12" Click="LoginButton_Click" Content="Log In" Width="100" Height="31" Margin="50,0,0,0" FontFamily="Arial" Visibility="Visible" IsEnabled="True" MouseEnter="LoginButton_MouseEnter" /> <Button Name="OptionsButton" Content="Options" Width="100" Height="31" Margin="20,0,0,0" FontFamily="Arial" FontSize="12" Click="OptionsButton_Click" Visibility="Hidden" IsEnabled="False"/> </StackPanel>
The resouces section is commented out because I tried this and it did not work. My login button has the following event handler attached.
LoginButton.MouseEnter += new MouseEventHandler(LoginButton_MouseEnter);
The method that handles this:
private void LoginButton_MouseEnter(object sender, MouseEventArgs e) { MessageBox.Show("Made in the login button listener for mouseOver"); LoginButton.Visibility = Visibility.Visible; }
When I launch my application, nothing happens when I set the location where the button should be. However, if I first set the visibility of the login button to Visible, I can see the button, and when I click on it, my logical login method for user login is overridden, and I am offered a window with a message in the MouseEventListener method for "Made in the login button listener for mouseOver ". Not only that, but I get two of these messages (as soon as I click OK for the first time, it immediately appears again) I'm not sure why this does not work and why my click event method is ignored and now the mouseEvent method is called.
Any thoughts or help would be appreciated, thanks!
source share