引用Windows Phone七中的合并资源字典失败 [英] Referencing a merged resource dictionary in windows phone seven failing

查看:91
本文介绍了引用Windows Phone七中的合并资源字典失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用MVVMLight框架构建WP7应用程序.我想将资源字典添加到我的app.xaml中,但是这样做失败.这是来自app.xaml的小贴士

I am currently building a WP7 app using the MVVMLight framework. I would like to add a resource dictionary to my app.xaml, however when I do it fails. Here is a snipit from the 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>

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

Because I am using a ViewModelLocator that has a key, I get an error warning me that I can not mix resources with and without keys. After adding a key to my resource dictionary It looks like the following:

    <ResourceDictionary x:Key="resourceDictionary">
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="View/StyleResourceDictionary.xaml"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>

在资源字典中,我有一个键为"TitleTemplate"的样式.无论哪种情况,当我尝试从我的一个视图中引用资源字典时,它都会失败.在我看来,示例代码如下:

In the resource dictionary I have a style with the key "TitleTemplate". In either case when I try to reference the resource dictionary from one of my views it fails. Sample code from my view is bellow:

<TextBlock Name="TB_ContactNameLabel" 
           Text="contact" 
           Style="{StaticResource TitleTemplate}"/>

设计人员立即给我错误无法解决资源'TitleTemplate'".如果我引用资源字典的键(即resourceDictionary),则不会引发任何错误,但显然不会执行任何操作.最后,如果我将resourceDictionary直接添加到其资源中的页面中,而不是将app.xaml添加到页面,则一切正常.我不想将其添加到我计划使用的每个视图中.我在这里想念什么吗?

The designer immediately gives me the error "The resource 'TitleTemplate' could not be resolved". If I reference the key of the resourced dictionary (ie: resourceDictionary) no error is thrown but it doesn't do anything obviously. Finally if I add the resourceDictionary directly to the page in its resources, instead of the app.xaml everything works fine. I do not want to have to add it to each view I plan to use. Am I missing something here?

推荐答案

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

Your application resources should look like the following:

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

这篇关于引用Windows Phone七中的合并资源字典失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆