I am attempting to fill a rectangle, called Key, with a Local Resource (a LinearGradientBrush) called PrecipHour. When I run the code below, a nullreferenceexception is thrown - Can I not just cast a resource as a LinearGradientBrush?
C#
key.Fill = (LinearGradientBrush)this.Resources["PrecipHour"];
XAML
<LinearGradientBrush x:Key="PrecipHour" EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FF661C00" Offset="0"/>
<GradientStop Color="#FF0011BF" Offset="1"/>
<GradientStop Color="#FF265CEC" Offset="0.838"/>
<GradientStop Color="#FF2EFF00" Offset="0.445"/>
<GradientStop Color="#FFF3FF00" Offset="0.253"/>
<GradientStop Color="Red" Offset="0.125"/>
<GradientStop Color="#FF65E040" Offset="0.626"/>
</LinearGradientBrush>