【问题标题】:WPF Tile Background with png image and solid color带有png图像和纯色的WPF平铺背景
【发布时间】:2014-05-02 11:37:27
【问题描述】:

我有这样的代码

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

【问题讨论】:

标签: c# wpf background tile


【解决方案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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多