سؤال

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