I have a simple solution: instead of inheriting, you can create a class that modifies the Brush properties by inserting attached properties. For example: I created a class called "HatchBrushes" that can create 55 DrawingBrushes with delayed hatching styles (similar to WinForms HatchBrush .. Actually this part of the code belongs to another programmer) The HatchBrushes class defines 4 attached properties that control the appearance of the hatch: HatchStyle , Background, Foreground, and PenThickness. All of these properties register a subclass of PropertyChangedCallBck called "OnHatchChanged", where I can change the properties of the DrawingBrush:
Shared Sub OnHatchChanged(d As DependencyObject, e As DependencyPropertyChangedEventArgs) Dim DBrush = TryCast(d, DrawingBrush) If DBrush Is Nothing Then Return Dim B = GetHatchBrush(GetHatchStyle(DBrush), GetBackground(DBrush), GetForeground(DBrush), GetPenThickness(DBrush)) DBrush.Drawing = B.Drawing.CloneCurrentValue DBrush.Stretch = B.Stretch DBrush.ViewportUnits = B.ViewportUnits DBrush.Viewport = B.Viewport DBrush.TileMode = B.TileMode End Sub
Note that "GetHatchBrush" is a function that creates a DrawingBrush with the desired HatchStyle. I will not write it here because it is too long.
Now I can color the window background using the Horizontal-Line Hatch with simole xaml code as follows:
<DrawingBrush c:HatchBrushes.HatchStyle="Horizontal" c:HatchBrushes.Background="Red" c:HatchBrushes.Foreground="Yellow" c:HatchBrushes.PenThickness="2"/>
Mohammad hamdy
source share