开发者

Create Custom Brush With Png(transparent) Image and a Background Color

开发者 https://www.devze.com 2023-01-30 21:51 出处:网络
I want to create a custom brush in WPF that will be applied to a rectangle. Fill= myCustomBrush. theCustomBrush contains a png image (ImageBrush) ,and contanins a color in background (SolidColor开发者

I want to create a custom brush in WPF that will be applied to a rectangle. Fill= myCustomBrush. theCustomBrush contains a png image (ImageBrush) ,and contanins a color in background (SolidColor开发者_开发问答Brush). I want to create a custombrush with this two standards brushes.

Thanks for Help.


You can use VisualBrush for this. Example

<SolidColorBrush x:Key="MyBackgroundColor" Color="Green"/>
<VisualBrush x:Key="RectangleBrush">
    <VisualBrush.Visual>
        <Grid>
            <Rectangle Fill="{StaticResource MyBackgroundColor}"/>
            <Image Source="BackgroundImageSource"/>
        </Grid>
    </VisualBrush.Visual>
</VisualBrush>

<!-- ... -->

<Rectangle Fill="{StaticResource RectangleBrush}"/>
0

精彩评论

暂无评论...
验证码 换一张
取 消