2014-05-02 66 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>