I'm trying to reference a LinearGradientBrush with the XAML parser, but it can't identify the object and I get the exception:
"Cannot create unknown type 'LinearGradientBrush'"
Is it possible to make this type recognized at runtime?
Here is the code I'm using:
public static class CustomBrushes
{
public static Brush LinGrad_Bevel()
{
StringReader sr = new StringReader(@"<LinearGradientBrush EndPoint='0.5,1' MappingMode='RelativeToBoundingBox' StartPoint='0.5,0'>
<GradientStop Color='#00F7F7F7' Offset='0'/>
<GradientStop Offset='1'/>
<GradientStop Color='Black' Offset='0.741'/>
<GradientStop Color='Black' Offset='0.75'/>
<GradientStop Color='White' Offset='0.25'/>
</LinearGradientBrush>");
XmlReader xr = XmlReader.Create(sr);
return (Brush)XamlReader.Load(xr);
}
}
I really don't like programing in XAML (especially because most of what I do is design dependent on runtime program flow, but some objects are just way easier to prototype in it than C# and I'd prefer to be able to employ this method...
I've read I'm supposed to include a line like this somewhere, but honestly I don't understand why and it doesn't seem to work if I stick it under all the "usings"
[assembly: XmlnsDefinition("http://schemas.microsoft.com/netfx/2007/xaml/presentation" , "System.Windows.Media")]
Anyway, any help with runtime parsing of XAML in C# code files would be appreciated.