值超出范围异常将ResourceDictionary Source设置为CustomControl的generic.XAML

时间:2010-05-12 06:21:53

标签: wpf silverlight silverlight-3.0 custom-controls

我有一个自定义控件,其中包含Themes文件夹中的generic.xaml。我已将构建操作设置为Resource。

现在从App.xaml我使用:

设置对DLL的引用
xmlns:localFolder="clr-namespace:customControl;assembly=customControl"

设置引用后,我尝试合并App.xaml中的资源字典,如下所示:

<Application.Resources>

        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="localFolder;component/Themes/generic.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>

</Application.Resources>

但是在运行我的应用程序时,我得到以下XAMLParseException

Attribute localFolder;component/Themes/generic.xaml value is out of range. [Line: 16 Position: 44]

1 个答案:

答案 0 :(得分:1)

Source应采用Uri格式 - /assembly-name;component/path-to-resource。您无法使用xmlns:localFolder="..."定义XML命名空间,然后在URI字符串中使用它。以下是some reading所接受的格式。