簡體   English   中英

WPF窗口中的透明PNG

[英]Transparent PNG in WPF window

我嘗試將具有透明度的PNG圖像應用到整個窗口,但窗口始終是白色的。

有任何線索可以看到PNG的透明度嗎?

謝謝!

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"

我的窗口有一個默認背景,如果沒有在窗口上設置Background =“Transparent”(這可能是由於Expression Blend),這對我來說不起作用,以防萬一有人有這樣的類似問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM