DotNet Mirror
  DNM facebook   DNM Google+   DNM Twitter   

Provide value on 'System.Windows.StaticResourceExtension' threw an exception - System.Windows.Markup.XamlParseException

By Ashok Nalam on 08 Jul 2013 | Category: WPF | Tagged: error .NET 
  Discuss Add Comment   |  
Add rating Rate this resource   
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.
  Discuss Add Comment    
Add rating Rate this resource   
About the Contributor
Member Since : 10 Dec 2012
Member Points (Level) : 9526  (Professional)
Location : INDIA
Home Page : http://dotnetmirror.com
About : I am admin of this site.
Rate this resource
 
Add your Comment
Name Email WebSite
Captcha Refresh


Comments (0)
No comments found, click here to add comment.
 
cheap jordans|wholesale air max|wholesale jordans|wholesale jewelry|wholesale jerseys