WPF窗口中的透明PNG [英] Transparent PNG in WPF window
本文介绍了WPF窗口中的透明PNG的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试将具有透明度的 PNG 图像应用于整个窗口,但窗口始终为白色.
I try to apply PNG image that has transparency into the whole window but the window is always white.
有什么线索可以看到 PNG 的透明度吗?
Any clue to see PNG with its transparency?
谢谢!
C#
public SplashScreen()
{
InitializeComponent();
var myBrush = new ImageBrush();
var image = new Image
{
Source = new BitmapImage(
new Uri(
"pack://application:,,,/MyApp;component/Images/Logo.png"))
};
myBrush.ImageSource = image.Source;
Background = myBrush;
}
XAML
<Window x:Class="MyApp.SplashScreen"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Topmost="True"
Title="SplashScreen" Height="400" Width="400" WindowStartupLocation="CenterScreen" WindowStyle="None"
BorderThickness="5" ShowInTaskbar="False" ResizeMode="NoResize" >
<Grid Name="MainGrid">
<Label FontSize="10" Height="20" Foreground="White" Margin="0,0,0,0" Padding="10,0,0,5" Name="statusLabel" VerticalAlignment="Bottom"></Label>
<TextBlock Visibility="Collapsed" FontSize="10" Foreground="White" Margin="18,110,18,30" Name="appInfo" TextAlignment="Center">
</TextBlock>
<TextBlock Visibility="Collapsed" FontSize="20" Foreground="White" Margin="0,83,0,90" Name="version" TextAlignment="Center">
</TextBlock>
</Grid>
</Window>
推荐答案
海量信息 这里.我认为您缺少的部分是窗口上的 AllowsTransparency="True"
.
Lots of information here. I think the piece you're missing is AllowsTransparency="True"
on your window.
这篇关于WPF窗口中的透明PNG的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文