Windows phone 7 在Windows Phone中访问ResourceDictionary中的数据模板

Windows phone 7 在Windows Phone中访问ResourceDictionary中的数据模板,windows-phone-7,datatemplate,resourcedictionary,Windows Phone 7,Datatemplate,Resourcedictionary,我在ResourceDictionary“style1.xaml”中定义了一个数据模板: <ResourceDictionary xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:

我在ResourceDictionary“style1.xaml”中定义了一个数据模板:

<ResourceDictionary
    xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >

    <DataTemplate x:Key="BlogDataTemplate">
        <Grid Margin="0,0,6,20" Width="400" Height="210">
            <Grid VerticalAlignment="Bottom" Background="#A6000000">
                <TextBlock Text="{Binding title}" Style="{StaticResource PhoneTextExtraLargeStyle}" Foreground="White" Margin="6" FontSize="25" TextWrapping="Wrap"/>
            </Grid>
        </Grid>
    </DataTemplate>

</ResourceDictionary>
通过调试,我可以确保style1.xaml已经合并,然后在MainPage.xmal中我有一个列表框,我将ItemTemplate定义为

 <ListBox x:Name="listbox" ItemsSource="{Binding}" CacheMode="BitmapCache" ItemTemplate="{StaticResource BlogDataTemplate}"/>

但当我部署应用程序时,它导致了一个“未指定的错误”

那么如何在Windows Phone中访问ResourceDictionary中的DataTemplate呢


提前感谢。

不要使用LoadDictionary代码,而是尝试通过以下操作将ResourceDictionary与App.Xaml中的Xaml合并(在App.Xaml中,在Application.Resources中):



Hi codechinchilla,我做了你在答案中发布的事情,但它引发了异常无法找到名为/key BlogDataTemplate的资源如何消除此异常?嘿,Android_疯狂-你能发布你的App.xaml和你正在使用的资源字典xaml吗?对于社区,你是如何着手解决你的问题的?谢谢
 <ListBox x:Name="listbox" ItemsSource="{Binding}" CacheMode="BitmapCache" ItemTemplate="{StaticResource BlogDataTemplate}"/>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="Themes/style1.xaml"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>