开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜