【问题标题】:WPF XAML How to change background to match the main WindowsWPF XAML 如何更改背景以匹配主窗口
【发布时间】:2018-04-06 16:47:50
【问题描述】:

这是一个简单的问题,但我找不到解决这个问题的正确答案。

XAML 代码:

<Window x:Class="IDSLogUtilityWPF.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Height="385" Width="622" WindowStartupLocation="CenterScreen" Background="White">
    <DockPanel Margin="1" LastChildFill="False">
        <DockPanel.Background>
            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                <GradientStop Color="Black" Offset="0"/>
                <GradientStop Color="#FFDAC7C7" Offset="1"/>
            </LinearGradientBrush>
        </DockPanel.Background>
        <Menu DockPanel.Dock="Top" Height="25">
            <MenuItem Header="File">
                <MenuItem Header="Exit" Click="MenuItem_FileExit"/>
            </MenuItem>
            <MenuItem Header="Settings">
                <MenuItem Header="CAN Interface" Click="MenuItem_CAN_Interface"/>
            </MenuItem>
            <MenuItem Header="Help">
                <MenuItem Header="About" Click="MenuItem_HelpAbout"/>
            </MenuItem>
        </Menu>
        <DockPanel Margin="10" Width="590" Height="80" DockPanel.Dock="Bottom" LastChildFill="False">
            <Image Source="images\gateway.bmp" DockPanel.Dock="Bottom" Stretch="Fill" RenderOptions.BitmapScalingMode="Fant" Width="140" Height="60"/>
            <Image Source="images\gateway.bmp" Stretch="None" DockPanel.Dock="Left" Margin="0,30,0,-50"/>
            <Image Source="images\gateway.bmp" Stretch="None" DockPanel.Dock="Right" Margin="0,30,5,-50"/>

        </DockPanel>

    </DockPanel>
</Window>

所以我有一个 WPF XAML 应用程序,其中有主窗口,我想添加几个背景显然与窗口不同的图像。

如何操作每个图像的背景以匹配窗口(在这种情况下,窗口背景是线性渐变画笔,但如果不可能,我可以使用纯色背景。

如您所见,图像的外观看起来很丑。

谢谢,非常感谢任何帮助。

【问题讨论】:

  • 研究使用透明背景的 png 图片,have a look here
  • 我已经阅读了那个答案,但它什么也没做。在窗口中添加了 Background="Transparent" AllowsTransparency="True" 并将我的图像从 bmp 转换为 png 并且图像仍然以白色背景显示。
  • 确保编辑生成的 png 以使背景透明。由于 bmp 不支持透明度,因此直接转换将保留白色区域。将它们编辑为真正透明,然后应用链接的解决方案。

标签: wpf image xaml background


【解决方案1】:

您的 .bmp 图像文件本身包含白色背景。尝试使用 .png 格式的图片。

【讨论】:

    猜你喜欢
    • 2022-12-10
    • 2011-10-24
    • 2014-07-15
    • 2019-01-15
    • 2010-11-21
    • 1970-01-01
    • 2011-06-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多