Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF button background mouseenter and leave not working as expected
    text
    copied!<p>I have a WPF button like so:</p> <pre><code>&lt;Page.Resources&gt; &lt;ImageBrush x:Key="black_pane_normal" ImageSource="/Images/TroubleShooting/black_pane_clear.png" /&gt; &lt;/Page.Resources&gt; &lt;Button x:Name="ButtonBlackPane" Background="{StaticResource black_pane_normal}" HorizontalAlignment="Left" VerticalAlignment="Top" Width="157" Height="136" MouseEnter="ButtonBlackPane_MouseEnter" MouseLeave="ButtonBlackPane_MouseLeave" Click="ButtonBlackPane_Click" RenderTransformOrigin="0.533,0.281" Margin="189,199,0,0"/&gt; </code></pre> <p>My C# code behind is:</p> <pre><code> BitmapSource _black_pane_yellow_border = Imaging.CreateBitmapSourceFromHBitmap(InstallerToolkit.Properties.Resources.black_pane_yellow.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); BitmapSource _black_pane_no_border = Imaging.CreateBitmapSourceFromHBitmap(InstallerToolkit.Properties.Resources.black_pane_clear.GetHbitmap(), IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); private void ButtonBlackPane_MouseEnter(object sender, MouseEventArgs e) { ButtonBlackPane.Background = new ImageBrush(_black_pane_yellow_border); } private void ButtonBlackPane_MouseLeave(object sender, MouseEventArgs e) { ButtonBlackPane.Background = new ImageBrush(_black_pane_no_border); } </code></pre> <p>My first problem is that my image does not fill the whole button background, how do I get this to fill it?</p> <p>My second problem is that when the mouse enters the button, the correct background image gets displayed for a moment and then the default gray button image shows and my image goes away, how can I solve this?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload