2015-12-30 107 views
0

这是我ListDictionary.xaml无法设置的ItemTemplate到ListView的,因为它没有找到资源

<ResourceDictionary 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
xmlns:local="using:Seminarska"> 

<DataTemplate x:Name="ArticleListTemplate"> 
    <StackPanel Orientation="Horizontal"> 
     <TextBlock Text="{Binding Title}" 
        Margin="5" 
        Style="{StaticResource BodyTextBlockStyle}" /> 
    </StackPanel> 
</DataTemplate> 

</ResourceDictionary> 

而且我MainPage.xaml中

<Page 
x:Class="Seminarska.MainPage" 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
xmlns:local="using:Seminarska" 
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
mc:Ignorable="d"> 

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> 
    <Grid.RowDefinitions> 
     <RowDefinition Height="80" /> 
     <RowDefinition Height="*" /> 
    </Grid.RowDefinitions> 

    <ProgressRing HorizontalAlignment="Center" 
        VerticalAlignment="Center" 
        Visibility="Collapsed" 
        Height="100" 
        Width="100" 
        x:Name="pbLoading" 
        Grid.RowSpan="3" /> 

    <TextBlock Style="{StaticResource HeaderTextBlockStyle}" 
       Grid.Row="0" 
       Margin="10,0,0,0" 
       Text="My articles" 
       VerticalAlignment="Center" 
       HorizontalAlignment="Center" /> 

    <ListView x:Name="lvData" 
       Grid.Row="1" 
       SelectionChanged="LvData_OnSelectionChanged" 
       ItemTemplate="{StaticResource ArticleListTemplate}" 
       VerticalAlignment="Stretch" 
       HorizontalAlignment="Left"/> 
</Grid> 
</Page> 

正如你可以看到,我想将ItemTemplate设置为ListView,但没有找到它。它说:

资源'ArticleListTemplate'无法解析。

+0

你在哪里导入/使用ListDictionary? – dkozl

+0

啊...我不知道。我完全不熟悉Windows Phone开发。你能让我知道我是怎么做到的吗? – Guy

回答

1

假设你没有这样做,在应用程序资源,例如为了从字典文件访问资源,你需要使用它第一

<Page> 
    <Page.Resources> 
     <ResourceDictionary > 
     <ResourceDictionary.MergedDictionaries> 
      <ResourceDictionary Source="/path/to/file/ListDictionary.xaml"/> 
     </ResourceDictionary.MergedDictionaries> 
     </ResourceDictionary> 
    </Page.Resources> 
    <!-- --> 
</Page> 

DataTemplate你需要使用x:Key代替x:Name

<DataTemplate x:Key="ArticleListTemplate"> 
+0

是的,就是这样:)谢谢! – Guy