【问题标题】:Transparent PNG in WPF windowWPF窗口中的透明PNG
【发布时间】:2012-10-15 17:35:55
【问题描述】:

我尝试将具有透明度的 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>

【问题讨论】:

    标签: c# wpf xaml


    【解决方案1】:

    大量信息here。我认为您缺少的部分是您窗口上的AllowsTransparency="True"

    【讨论】:

      【解决方案2】:

      我的窗口有一个默认背景,如果没有在窗口上设置 Background="Transparent"(可能是由于 Expression Blend),这对我不起作用,以防万一有人遇到类似的问题。

      【讨论】:

        猜你喜欢
        • 2014-05-08
        • 1970-01-01
        • 2011-03-26
        • 2020-08-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-06-13
        • 2015-10-25
        相关资源
        最近更新 更多