问题
I have an ImageBrush and a SolidColorBrush. The thing is that I, now, want to set my canvas background with these properties.
I can easily set my background to either my ImageBrush or my SolidColorBrush but can I do a sort of merge ? The thing is that my ImageBrush.Stretch is set to Uniform so I can see the background color behind ! (It wouldn't be the case with "Fill")
Now, Brush is an abstract class so the solution I image is to extend it but that really is a lot of work for a thing that sounds simple and common to me...
Isn't there any other solution ?
回答1:
What about this, although it has the drawback that the image's absolute size and, more important, the aspect ratio is ignored. But it may give you a hint.
<Canvas>
<Canvas.Background>
<DrawingBrush>
<DrawingBrush.Drawing>
<DrawingGroup>
<GeometryDrawing Brush="Orange">
<GeometryDrawing.Geometry>
<RectangleGeometry Rect="0,0,1,1"/>
</GeometryDrawing.Geometry>
</GeometryDrawing>
<ImageDrawing ImageSource="C:\Users\Public\Pictures\Sample Pictures\Desert.jpg" Rect="0.2,0.2,0.6,0.6" />
</DrawingGroup>
</DrawingBrush.Drawing>
</DrawingBrush>
</Canvas.Background>
</Canvas>
来源:https://stackoverflow.com/questions/9196194/merge-an-imagebrush-and-a-solidcolorbrush-as-a-background-of-a-canvas