wpf - 为 WPF 表单组合图像和纯色背景

标签 wpf background

我有一个正在构建的 WPF 表单。我想为窗口指定一个背景图像,这很容易。但是,我还想指定一种颜色,以便图像未覆盖的表单区域为白色。我已经看到一些示例显示使用两种不同的背景画笔,但是当我尝试 VS.NET 时告诉我我不能有多个画笔。

这是我正在使用的 XAML

<Window x:Class="Consent.Client.Shell"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:cal="http://www.codeplex.com/CompositeWPF"
    Title="Shell" WindowStyle="None" WindowState="Maximized" FontSize="24">
    <Window.Background>
        <ImageBrush AlignmentX="Left" AlignmentY="Top"  Stretch="None" TileMode="None" ImageSource="logo_header2.png" />
    </Window.Background>
    <ItemsControl Background="White" VerticalAlignment="Center" cal:RegionManager.RegionName="MainRegion" >
    </ItemsControl>
</Window>

这对图像很有用,但图像未覆盖的背景是黑色的。怎么让它变白?改变图像本身并不是一个真正的选择。

最佳答案

试试这个(我删除了与问题不直接相关的所有内容以使代码更清晰):

<Window x:Class="Consent.Client.Shell"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Background="White">
   <Grid>
      <Grid.Background>
         <ImageBrush ImageSource="logo_header2.png" />
      </Grid.Background>
      <ItemsControl>
      </ItemsControl>
   </Grid>
</Window>

基本上,将窗口的背景设置为图像颜色的后面,而不是在窗口中放置一个网格并为网格提供背景图像,将所有内容放在网格内而不是直接在窗口中。

关于wpf - 为 WPF 表单组合图像和纯色背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/512869/

相关文章:

wpf - 以编程方式显示行详细信息

wpf - WPF和Powershell,需要知道如何向控件元素添加样式

.net - 在VS中快速创建依赖项属性

javascript - Chrome 扩展程序后台页面的快捷方式?

android - 更改选择/单击 ListView 项目的背景 - Android

c# - 将 DataGridComboBoxColumn 值传递给 ObjectDataProvider 的 MethodParameter

wpf - 删除WPF ListView/GridView高亮镶边

html - 如何使用CSS背景属性?

html - 使用 webkit 更改主体背景颜色会导致故障

background - 如何在前台后台接收消息 - React Native?