Is it possible to combine multiple DrawingBrushes into one or, alternatively, is there a way to assign multiple Brushes to my Grid?
<Grid Name="gridContainer" Background="{StaticResource GridTile, RectangeGridTile}">
obviously the above code would not work. Source code:
<DrawingBrush x:Key="GridTile" Viewport="0,0,4,16" ViewportUnits="Absolute" TileMode="Tile">
<DrawingBrush.Drawing>
<DrawingGroup>
<GeometryDrawing Geometry="M0,0 L1,0 1,0.05, 0,0.05Z" Brush="Black" />
<GeometryDrawing Geometry="M0,0 L0,1 0.1,1, 0.1,0Z" Brush="Black" />
</DrawingGroup>
</DrawingBrush.Drawing>
</DrawingBrush>
<DrawingBrush x:Key="RectangeGridTile" Viewport="0,0,120,48" ViewportUnits="Absolute" TileMode="Tile">
<DrawingBrush.Drawing >
<DrawingGroup>
<GeometryDrawing Geometry="M0,0 L1,0 1,0.05, 0,0.05Z" Brush="Black" />
<GeometryDrawing Geometry="M0,0 L0,1 0.1,1, 0.1,0Z" Brush="Black" />
</DrawingGroup>
</DrawingBrush.Drawing>
</DrawingBrush>
custom brushes are not supported in WPF (brush types are
internaland cannot be inherited from), so creating a brush is not possible.You could use a MarkupExtension to simulate the behaviour of a custom brush, which allows you to use XAML syntax and provide a custom value, which allows us to use the built-in SolidColorBrush set to the valueof, lets say, two mixing colors:
Which can then be used from XAML as you would a normal brush:
Or by using the markup extension syntax:
Note:
You cannot use
DynamicResourceorStaticResourcereferences to bind the values to other resources in your application. MarkupExtension is not a DependencyObject, and resource binding only works on DependencyObjects; the built-in Brushes are DependencyObjects, which is why binding works with traditional brushes.