In WPF application, if you get error message as "Provide value on 'System.Windows.StaticResourceExtension' threw an exception.' Line number 'X' and line position 'XXX'" use the below resolution.Error Code:<Window x:Class="StaticResourceExtension"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="StaticResourceExtension Error" Height="300" Width="300">
<StackPanel>
<Rectangle Height="50" Fill="{StaticResource brushflag}">
</Rectangle>
</StackPanel>
<Window.Resources>
<LinearGradientBrush x:Key="brushflag">
<GradientStop Offset="0" Color="Red" />
<GradientStop Offset="0.5" Color="White" />
<GradientStop Offset="1" Color="Green" />
</LinearGradientBrush>
</Window.Resources>
</Window> If you run the above code. it throws exception as "Provide value on 'System.Windows.StaticResourceExtension' threw an exception.' Line number '6' and line position '20'."Resolution:The inner exception message shows "Cannot find resource named 'brushflag'. Resource names are case sensitive.". Which means rectangle fill attribute is not able to find the resource key 'brushflag'.
So move the <Window.Resources> ... </Window.Resources> to the top of your StackPanel definition.
Note: StaticResource needs reference before using it.
|