Error using ResourceDictionary in Silverlight

In my Silverlight application, I have a UserControl, and I want to reference the StaticResource in a ResourceDictionary, which is in a separate XAML file.

My UserControl is as follows:

<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>

My SampleData.xaml file looks like this:

<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>

I have a SampleData.xaml file installed in the Content assembly action , and when I start the application, I get the error AG_E_PARSER_BAD_TYPE [Line: 5 Position: 44] in the InitializeComponent () line of the constructor for my UserControl.

What causes this error and how can I refer to this resource correctly?

+3
source share
2

: -

 xmlns:Headache="clr-namespace:ResourceDictionaryHeadache"

PersonList , ResourceDictionaryHeadache?

, , XAML PersonList.

D'Oh! , / Source SampleData.xaml Build Action "".

, XAML " ", " " xaml: -

<UserControl.Resources> 
    <ResourceDictionary Source="SampleData.xaml" /> 
</UserControl.Resources>
+2

" " , :

<ResourceDictionary Source="/AssemblyName;component/sampledata.xaml" />

, , DLL.

+4

Source: https://habr.com/ru/post/1727720/


All Articles