문제

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 (SolidColorBrush). 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}"/>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top