WPF Bitmap transparent background turns black


I have a listbox with Items that all have a random background color. In each Item of the listbox i want to display a Bitmap picture. Now for some reason the background of each bitmap (which I've set to Color.Transparent) Shows up black.

Here a picture of how it looks

<a href="https://i.stack.imgur.com/ESuCO.png" rel="nofollow"><img alt="Background not transparent" class="b-lazy" data-src="https://i.stack.imgur.com/ESuCO.png" data-original="https://i.stack.imgur.com/ESuCO.png" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" /></a>

My code for the listbox:

<WrapPanel Grid.Row="1" Grid.Column="1" Margin="6" > <ListBox x:Name="CharListBox" BorderThickness="0" ScrollViewer.VerticalScrollBarVisibility="Hidden" ItemsSource="{Binding ListToDisplay, UpdateSourceTrigger=PropertyChanged}" ItemTemplate="{DynamicResource ItemTemplate1}" SelectionChanged="SelectionChangedNewCharSelected"> </ListBox> </WrapPanel>

The item template (I removed everything beside the image part for bettter overview):

<DataTemplate x:Key="ItemTemplate1" > <Image Source="{Binding OutfitImageSource, UpdateSourceTrigger=PropertyChanged}" Height="40" Width="40" /> </DataTemplate>

The Binding binds to a BitmapSource.

Is it possible that bitmaps dont have actual transparency, its just shown as black? I also tried to add AllowsTransparency="True" to the window properties, this just lead to the window crashing instantly..

Thank you for helping in advance!

<strong>update:</strong> AllowsTransparency works if i set WindowStyle="None" but it still does not fix the problem with the untransparent bitmaps.


As reported in this <a href="https://superuser.com/a/180960" rel="nofollow">answer</a>


Bitmaps (i.e. files with .BMP extension) do not natively support transparency: you need to save as a different format like PNG.


You can find the same info also <a href="http://gimpchat.com/viewtopic.php?f=8&t=1290#p14668" rel="nofollow">here</a>.

So it does not depend on your XAML or your code. Just save your bitmaps as PNG files and then use those files for your application.