如何在页面中使用ResourceDictionary

时间:2013-10-18 05:07:01

标签: xaml windows-phone-7 windows-phone-8 resourcedictionary

在下面的http://www.geekchamp.com/articles/all-about-resourcedictionary-in-wp7中,我想在我的应用程序中使用ResourceDictionary。但是我在我的页面的xaml中收到错误,在我的应用程序的根目录中显示An error occurred while finding the resource dictionary "/Resources/ContactListDictionary.xaml". I have created a ResourceDictionary named ContactListDictionary.xaml located in Views / Resources`子文件夹,我正在尝试将其添加到我的页面,如下所示

<phone:PhoneApplicationPage.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="/Resources/ContactListDictionary.xaml"/> <!-- Error -->
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</phone:PhoneApplicationPage.Resources>

我错过了什么?我在ContactListDictionary.xaml

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

<!-- Resource dictionary entries should be defined here. -->
<DataTemplate x:Key="ContactItemTemplate">
    <Border HorizontalAlignment="Stretch" BorderBrush="#99FFFFFF" BorderThickness="1" Margin="0,10">
        <StackPanel  Margin="10" HorizontalAlignment="Stretch" >
            <TextBlock Text="{Binding DisplayName}" Style="{StaticResource TextBlockTitleXLargeStyle}"/>
            <TextBlock Text="{Binding Path=LocalizedResources.Resources_ContactListDictionary_PhoneNumbers, Source={StaticResource LocalizedStrings}}" Style="{StaticResource TextBlockTitleMediumStyle}"/>
            <ListBox ItemsSource="{Binding PhoneNumbers}" Margin="12,0" ScrollViewer.VerticalScrollBarVisibility="Disabled">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal" Margin="12,0,6,0" >
                            <!--<TextBlock Text="{Binding Kind}" Margin="12, 0, 6, 0" Style="{StaticResource TextBlockTitleMediumStyle}"/>-->
                            <TextBlock Text="{Binding PhoneNumber}" Style="{StaticResource TextBlockMediumStyle}"/>
                        </StackPanel>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
            <TextBlock Text="{Binding Path=LocalizedResources.Resources_ContactListDictionary_EmailAddresses, Source={StaticResource LocalizedStrings}}" Style="{StaticResource TextBlockTitleMediumStyle}"/>
            <ListBox ItemsSource="{Binding EmailAddresses}" Margin="12,0" ScrollViewer.VerticalScrollBarVisibility="Disabled">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal" Margin="12,0,6,0">
                            <!--<TextBlock Text="{Binding Kind}" Margin="12, 0, 6, 0" Style="{StaticResource TextBlockTitleMediumStyle}"/>-->
                            <TextBlock Text="{Binding EmailAddress}" Style="{StaticResource TextBlockMediumStyle}"/>
                        </StackPanel>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
            <TextBlock Text="{Binding Path=LocalizedResources.Resources_ContactListDictionary_Addresses, Source={StaticResource LocalizedStrings}}" Style="{StaticResource TextBlockTitleMediumStyle}"/>
            <ListBox ItemsSource="{Binding Addresses}" Margin="12,0" ScrollViewer.VerticalScrollBarVisibility="Disabled">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal" Margin="12,0,6,0">
                            <!--<TextBlock Text="{Binding Kind}" Margin="12, 0, 6, 0" Style="{StaticResource TextBlockTitleMediumStyle}" VerticalAlignment="Top"/>-->
                            <StackPanel>
                                <TextBlock Text="{Binding PhysicalAddress.AddressLine1}" Style="{StaticResource TextBlockMediumStyle}"/>
                                <TextBlock Text="{Binding PhysicalAddress.City}" Style="{StaticResource TextBlockMediumStyle}"/>
                            </StackPanel>
                        </StackPanel>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </StackPanel>
    </Border>
</DataTemplate>

<DataTemplate x:Key="ContactsGroupHeaderTemplate">
    <Border Background="{StaticResource PhoneAccentBrush}" Padding="{StaticResource PhoneTouchTargetOverhang}">
        <TextBlock Text="{Binding Title}" Style="{StaticResource PhoneTextLargeStyle}"/>
    </Border>
</DataTemplate>

<DataTemplate x:Key="ContactsGroupItemTemplate" >
    <Border Background="{StaticResource PhoneAccentBrush}" Margin="{StaticResource PhoneTouchTargetOverhang}" Padding="{StaticResource PhoneTouchTargetOverhang}">
        <TextBlock Text="{Binding Title}" Style="{StaticResource PhoneTextLargeStyle}"/>
    </Border>
</DataTemplate>

<ItemsPanelTemplate x:Key="ContactGroupViewTemplate">
    <toolkit:WrapPanel/>
</ItemsPanelTemplate>
</ResourceDictionary>

1 个答案:

答案 0 :(得分:1)

</ResourceDictionary>

末尾缺少ContactListDictionary.xaml关闭标记