app.xaml中的StaticResource在app.xaml引用的资源字典中找不到

时间:2012-12-20 22:25:18

标签: .net wpf staticresource

我遇到的情况是我试图解析资源字典中引用的数据模板中的可视化组件,引用app.xaml标记的静态资源,请参阅下面的示例。

/App.xaml

<Application 
    x:Class="App" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"      
    xmlns:composition="clr-namespace:Composition"
    ShutdownMode="OnMainWindowClose">
    <Application.Resources>
        <ResourceDictionary>
            <composition:ApplicationContainer x:Key="ApplicationContainer"/>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="pack://application:,,,/MyApp;component/Composition/DataTemplates.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>

/Composition/DataTemplates.xaml

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:projectvm="clr-namespace:ViewModels.ProjectManagement"
                    xmlns:unity="clr-namespace:Extensions">
    <DataTemplate DataType="{x:Type projectvm:ProjectDocument}">
        <ContentControl>
            <!-- Custom Extension that resolves a component from the composition container -->
            <unity:Resolve Container="{StaticResource ApplicationContainer}" TargetType="{x:Type projectvm:ProjectDocument}" ContractName="ProjectDocument"/>
        </ContentControl>
    </DataTemplate>
</ResourceDictionary> 

ERROR就在上面,统一:Resolve行找不到ApplicationContainer静态资源,我不明白为什么。

0 个答案:

没有答案