2014-05-02 62 views
0

WPF瓷砖背景我有这样与PNG图像和纯色

<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来实现吗?

+0

非常类似的问题... http://stackoverflow.com/a/14085305/ 1706610 – FodderZone

回答

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>