【问题标题】:How to display an image brush in the background of a border如何在边框背景中显示图像画笔
【发布时间】:2012-07-30 02:48:53
【问题描述】:

我正在尝试将图像显示为边框元素的背景

<Border>                
     <Border.Background>
        <ImageBrush Stretch="Fill">
            <ImageBrush.ImageSource>
                <BitmapImage UriSource="http://10.218.23.10/myPic.jpg" />
            </ImageBrush.ImageSource>
        </ImageBrush>
     </Border.Background>
</Border>

有人告诉我应该使用 ImageBrush 代替 Image

(1) 使用 ImageBrush 比 Image 有什么好处?

(2) 如果我使用 Image 显示我的图片,它实际上会显示图像

      <Border>
           <Image Source="http://10.218.23.10/myPic.jpg"/>
      </Border>

这种情况只能用图像来完成吗?

【问题讨论】:

    标签: wpf image imagebrush


    【解决方案1】:

    您的第一个代码可能不会显示任何内容,因为 Border 不占用任何空间或因为内容遮挡了背景,即图像。

    您是使用Image 还是ImageBrush 取决于您希望它的行为方式,Image 是一个参与布局的控件,而画笔只是用图像绘制某些东西。我几乎从不使用画笔,因为我的图像或经常图标或突出显示的东西,如果你有一些背景应该有一些设计或图案作为背景,那么画笔可能是一个不错的选择。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-24
      • 2012-02-11
      • 1970-01-01
      • 1970-01-01
      • 2021-07-03
      相关资源
      最近更新 更多