2015-12-30 60 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