在Windows Phone 7中引用合并的资源字典失败

fer*_*cs2 4 xaml resourcedictionary windows-phone-7 mvvm-light

我目前正在使用MVVMLight框架构建WP7应用程序.我想在我的app.xaml中添加一个资源字典,但是当我这样做时失败了.这是app.xaml的片段

<Application.Resources>
    <!--Global View Model Locator-->
    <vm:ViewModelLocator x:Key="Locator"
                         d:IsDataSource="True" />
    <!--Merged Resource Dictionaries-->
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="View/StyleResourceDictionary.xaml"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Application.Resources>
Run Code Online (Sandbox Code Playgroud)

因为我正在使用具有密钥的ViewModelLocator,所以我收到一条错误警告我,无论是否使用密钥,我都无法混合资源.将密钥添加到我的资源字典后它看起来如下所示:

    <ResourceDictionary x:Key="resourceDictionary">
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="View/StyleResourceDictionary.xaml"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
Run Code Online (Sandbox Code Playgroud)

在资源字典中,我有一个带有"TitleTemplate"键的样式.在任何一种情况下,当我尝试从我的一个视图中引用资源字典时,它都会失败.我的观点中的示例代码如下:

<TextBlock Name="TB_ContactNameLabel" 
           Text="contact" 
           Style="{StaticResource TitleTemplate}"/>
Run Code Online (Sandbox Code Playgroud)

设计师立即给我错误"资源'TitleTemplate'无法解析".如果我引用资源字典的键(即:resourceDictionary),则不会抛出任何错误,但它显然没有做任何事情.最后,如果我将resourceDictionary直接添加到其资源中的页面,而不是app.xaml,一切正常.我不想将它添加到我计划使用的每个视图中.我在这里错过了什么吗?

Sha*_*rot 8

您的应用程序资源应如下所示:

<Application.Resources>
    <!--Global View Model Locator-->
    <!--Merged Resource Dictionaries-->
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="View/StyleResourceDictionary.xaml"/>
        </ResourceDictionary.MergedDictionaries>
        <vm:ViewModelLocator x:Key="Locator" d:IsDataSource="True" />
    </ResourceDictionary>
</Application.Resources>
Run Code Online (Sandbox Code Playgroud)