WPF平铺背景与png图像和纯色

时间:2014-05-02 11:37:27

标签: c# wpf background tile

我有这样的代码

<Viewbox Grid.Row="1">
  <controls:Tile Name="tileInvoice" Click="tileInvoice_Click" VerticalAlignment="Stretch" ToolTip="{x:Static resx:omniLang.Invoice}">
    <controls:Tile.Background>
      <ImageBrush ImageSource="Resources/invoice.png" Stretch="Uniform"/>
    </controls:Tile.Background>
    <TextBlock Name="headerInvoice" Text="{x:Static resx:omniLang.Invoice}" FontSize="22" Foreground="Black" FontWeight="Bold" VerticalAlignment="Center" Margin="0,100,0,0" />
  </controls:Tile>
</Viewbox>

我很想使用纯色作为背景,仍然使用png图像。我已经完成了这些想法。我应该使用VisualBrush来实现这个目标吗?

1 个答案:

答案 0 :(得分:1)

显然,Background属性只能有一个值,因此您无法将两个背景设置为同一属性。但是,没有什么可以阻止您将控件放入容器控件并设置它的Background属性:

<Viewbox Grid.Row="1">
    <Grid Background="Red"> <!-- Set your solid colour here -->
        <controls:Tile Name="tileInvoice" Click="tileInvoice_Click" VerticalAlignment="Stretch" ToolTip="{x:Static resx:omniLang.Invoice}">
            <controls:Tile.Background>
                <ImageBrush ImageSource="Resources/invoice.png" Stretch="Uniform"/>
            </controls:Tile.Background>
            <TextBlock Name="headerInvoice" Text="{x:Static resx:omniLang.Invoice}" FontSize="22" Foreground="Black" FontWeight="Bold" VerticalAlignment="Center" Margin="0,100,0,0" />
        </controls:Tile>
    </Grid>
</Viewbox>