I tried every possible angle for a solution to making a custom brush, from using MarkupExtensions to messing around with TypeConverter attributes, then it dawwned on me: you simply create a wrapper class based on DependencyObject, create a DependencyProperty of type Brush, implement your customization then Bind to the Brush DependencyProperty.
Afterwards, put the custom brush in Resources
<l:CustomBrush x:Key="CustomBrush" Brush="Magenta" />
Then Bind to it:
<Line X1="0" Y1="-5" X2="200" Y2="-5"
Stroke="{Binding Source={StaticResource CustomBrush}, Path=Brush}"
StrokeThickness="12"/>
I think this is better than the MarkupExtension solution because you can't put one in Resources and therefore you have to redefine the custom settings every time you use it.
In any case, this would seem to be a simple solution to inheriting from any Wpf object, and with the flexibility of Bindings you can also bind to members of the wrapped Wpf object itself.
Here's the simple class:
public class CustomBrush : DependencyObject
{
public CustomBrush()
{
this.Brush = Brushes.Azure;
}
#region Brush DependencyProperty
[BindableAttribute(true)]
public Brush Brush
{
get { return (Brush)GetValue(BrushProperty); }
set { SetValue(BrushProperty, value); }
}
public static readonly DependencyProperty BrushProperty =
DependencyProperty.Register(
"Brush",
typeof(Brush),
typeof(CustomBrush),
new UIPropertyMetadata(null));
#endregion
}