【问题标题】:XAML: ImageBrush horizontal tiledXAML:ImageBrush 水平平铺
【发布时间】:2018-12-11 10:00:49
【问题描述】:

我已经在互联网上搜索以解决以下问题,但不幸的是我没有找到任何可行的解决方案。

我的目标是在使用画笔的对象底部有一个图像 x 重复的 ImageBrush。另外画笔应该有一个透明的边距,所以重复的图像不能“接触”容器的边框。

目前我能够重复图像 x 轴和 y 轴(我被卡住了......)。我使用以下 XAML:

<ImageBrush 
    x:Key="MandatoryIndicator" 
    ImageSource="image.png" 
    Stretch="None" 
    TileMode="Tile" 
    ViewportUnits="Absolute" 
    Viewport="0,0,16,16" 
    AlignmentY="Bottom"/>

它看起来像这样:

我喜欢这样:

如果你知道我必须如何修改我的画笔 XAML,那就太好了 c[~] =)

【问题讨论】:

  • 你不能只有一个额外的元素,例如一个矩形,“容器”底部的高度为 16。
  • @Clemens:很遗憾没有,因为只有画笔在我自己的控制之下,其余的不是我的代码......

标签: xaml imagebrush


【解决方案1】:

您可以使用带有两个嵌套元素的 VisualBrush,如下所示。透明边距需要外部边框(或其他一些外部元素)。

<VisualBrush Stretch="None" AlignmentX="Left" AlignmentY="Bottom">
    <VisualBrush.Visual>
        <Border Background="Transparent"
                Width="{Binding ActualWidth,
                        RelativeSource={RelativeSource AncestorType=FrameworkElement}}">
            <Rectangle Margin="10" Height="16">
                <Rectangle.Fill>
                    <ImageBrush ImageSource="image.png" TileMode="Tile"
                                Viewport="0,0,16,16" ViewportUnits="Absolute"/>
                </Rectangle.Fill>
            </Rectangle>
        </Border>
    </VisualBrush.Visual>
</VisualBrush>

【讨论】:

  • 完全符合我的需求。非常感谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-12-04
  • 2016-01-27
  • 2019-08-09
  • 1970-01-01
  • 2018-06-29
相关资源
最近更新 更多