我有一个我正在构建的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>
Run Code Online (Sandbox Code Playgroud)
这适用于图像,但图像未覆盖的背景为黑色.我怎么把它变成白色?改变图像本身并不是一种选择.
试试这个(我删除了与问题没有直接关系的一切,以使代码更清晰):
<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>
Run Code Online (Sandbox Code Playgroud)
基本上,将窗口的背景设置为图像颜色的背后,而不是在窗口中放置网格并给网格提供背景图像,将所有内容放在网格中而不是直接放在窗口中.
| 归档时间: |
|
| 查看次数: |
13715 次 |
| 最近记录: |