【发布时间】:2010-01-08 02:51:34
【问题描述】:
在我的 Silverlight 应用程序中,我有 UserControl,我想在单独的 XAML 文件中的 ResourceDictionary 中引用 StaticResource。
我的用户控件如下所示:
<UserControl x:Class="ResourceDictionaryHeadache.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
<UserControl.Resources>
<ResourceDictionary Source="/SampleData.xaml" />
</UserControl.Resources>
<Grid x:Name="LayoutRoot">
<ListBox HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
ItemsSource="{StaticResource SampleData}">
</ListBox>
</Grid>
</UserControl>
我的 SampleData.xaml 文件如下所示:
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Headache="clr-namespace:ResourceDictionaryHeadache">
<Headache:PersonList x:Key="SampleData">
<Headache:Person Name="Joe" Age="20" />
<Headache:Person Name="Sam" Age="25" />
<Headache:Person Name="Dave" Age="30" />
</Headache:PersonList>
我将 SampleData.xaml 文件设置为 Content 的构建操作,当我运行该应用程序时,我在 InitializeComponent() 行上收到 AG_E_PARSER_BAD_TYPE [Line: 5 Position: 44] 错误我的 UserControl 的构造函数。
是什么导致了这个错误,我该如何正确引用这个资源?
【问题讨论】:
-
有时在 VS 中设置公共语言运行时异常以捕获未处理的异常,您可以获得更多关于实际发生了什么的提示。 (按 control-alt-E,然后选中 CLRE 旁边的 Thrown)
标签: silverlight xaml silverlight-3.0