Note that there are some explanatory texts on larger screens.

plurals
  1. POError - Cannot find static resource in a WPF application
    text
    copied!<p>I'm learning WPF and started with <a href="http://msdn.microsoft.com/en-us/library/ms752299.aspx#" rel="noreferrer">this</a> MSDN tutorial.</p> <p>I was just following the tutorial. When I finished the code as per the tutorial and try to run I get an exception in a XAML page which says</p> <blockquote> <p>'Provide value on 'System.Windows.StaticResourceExtension' threw an exception.' Line number '27' and line position '55'." . And inner exception reveals that error is "Cannot find resource named 'personItemTemplate'. Resource names are case sensitive.".</p> </blockquote> <p>The culprit XAML is below.</p> <pre><code>&lt;Page x:Class="ExpenseIt.ExpenseItHome" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d" d:DesignHeight="321" d:DesignWidth="532" Title="ExpenseIt - Home"&gt; &lt;Grid Margin="10,0,10,10"&gt; &lt;Grid.ColumnDefinitions&gt; &lt;ColumnDefinition Width="230" /&gt; &lt;ColumnDefinition /&gt; &lt;/Grid.ColumnDefinitions&gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition /&gt; &lt;RowDefinition Height="Auto" /&gt; &lt;RowDefinition /&gt; &lt;RowDefinition Height="Auto" /&gt; &lt;/Grid.RowDefinitions&gt; &lt;Label Grid.Column="1" Style="{StaticResource headerTextStyle}"&gt;View Expense Report&lt;/Label&gt; &lt;!-- Resource List Label--&gt; &lt;Border Grid.Column="1" Grid.Row="1" Style="{StaticResource listHeaderStyle}"&gt; &lt;Label VerticalAlignment="Center" Foreground="White" FontWeight="Bold"&gt;Names&lt;/Label&gt; &lt;/Border&gt; &lt;!-- Resource List--&gt; &lt;ListBox Name="peopleListBox" Grid.Column="1" Grid.Row="2" ItemsSource="{Binding Source={StaticResource ExpenseDataSource}, XPath=Person}" ItemTemplate="{StaticResource personItemTemplate}"&gt; &lt;/ListBox&gt; &lt;!-- View button --&gt; &lt;Button Grid.Column="1" Grid.Row="3" Click="Button_Click" Style="{StaticResource buttonStyle}"&gt;View&lt;/Button&gt; &lt;!-- Set Background Image--&gt; &lt;Grid.Background&gt; &lt;ImageBrush ImageSource="watermark.png" /&gt; &lt;/Grid.Background&gt; &lt;Grid.Resources&gt; &lt;!-- Expense Report Data --&gt; &lt;XmlDataProvider x:Key="ExpenseDataSource" XPath="Expenses"&gt; &lt;x:XData&gt; &lt;Expenses xmlns=""&gt; &lt;Person Name="TommyVance" Department="Legal"&gt; &lt;Expense ExpenseType="Lunch" ExpenseAmount="50" /&gt; &lt;Expense ExpenseType="Transportation" ExpenseAmount="50" /&gt; &lt;/Person&gt; &lt;Person Name="PhilJackson" Department="Marketing"&gt; &lt;Expense ExpenseType="Document printing" ExpenseAmount="50"/&gt; &lt;Expense ExpenseType="Gift" ExpenseAmount="125" /&gt; &lt;/Person&gt; &lt;Person Name="PaulBriggs" Department="Engineering"&gt; &lt;Expense ExpenseType="Magazine subscription" ExpenseAmount="50"/&gt; &lt;Expense ExpenseType="New machine" ExpenseAmount="600" /&gt; &lt;Expense ExpenseType="Software" ExpenseAmount="500" /&gt; &lt;/Person&gt; &lt;Person Name="AlfredNobel" Department="Finance"&gt; &lt;Expense ExpenseType="Dinner" ExpenseAmount="100" /&gt; &lt;/Person&gt; &lt;/Expenses&gt; &lt;/x:XData&gt; &lt;/XmlDataProvider&gt; &lt;!-- Data Template to mention that Name should be fetched from the XMLDataProvider --&gt; &lt;!-- Name item template --&gt; &lt;DataTemplate x:Key="personItemTemplate"&gt; &lt;Label Content="{Binding XPath=@Name}"/&gt; &lt;/DataTemplate&gt; &lt;/Grid.Resources&gt; &lt;/Grid&gt; &lt;/Page&gt; </code></pre> <p>I have the required template inside the Grid resources and so adding it as a static resource. Still, it throws the exception that the datatemplate is not available.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload