I have a WPF button like so:
<Page.Resources>
<ImageBrush x:Key="black_pane_normal" ImageSource="/Images/TroubleShooting/black_pane_clear.png" />
</Page.Resources>
<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"/>
My C# code behind is:
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);
}
My first problem is that my image does not fill the whole button background, how do I get this to fill it?
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?