Windows phone 8 数据未显示在Itemview页面中

Windows phone 8 数据未显示在Itemview页面中,windows-phone-8,Windows Phone 8,我正在尝试为我的Windows 8.1集线器应用程序实现以下数据模型: namespace TrialAPP.Data { public class SamplePoemItem { public SamplePoemItem(String poemId, String poemtitle, String poemmean) { this.PoemId = poemId; this.PoemTitle = poemtitle; t

我正在尝试为我的Windows 8.1集线器应用程序实现以下数据模型:

namespace TrialAPP.Data
{
public class SamplePoemItem
{

    public SamplePoemItem(String poemId, String poemtitle, String poemmean)
    {
        this.PoemId = poemId;
        this.PoemTitle = poemtitle;
        this.PoemMean = poemmean;
    }
    public string PoemId { get; private set; }
    public string PoemTitle { get; private set; }
    public string PoemMean { get; private set; }
    public override string ToString()
    {
        return this.PoemTitle;
    }

}

/// <summary>
/// Generic item data model.
/// </summary>
public class SampleDataItem
{
    public SampleDataItem(String uniqueId, String title, String subtitle, String imagePath, String description, String content)
    {
        this.UniqueId = uniqueId;
        this.Title = title;
        this.Subtitle = subtitle;
        this.Description = description;
        this.ImagePath = imagePath;
        this.Content = content;
        this.Poems = new ObservableCollection<SamplePoemItem>();


    }

    public string UniqueId { get; private set; }
    public string Title { get; private set; }
    public string Subtitle { get; private set; }
    public string Description { get; private set; }
    public string ImagePath { get; private set; }
    public string Content { get; private set; }
    public ObservableCollection<SamplePoemItem> Poems { get; private set; }

    public override string ToString()
    {
        return this.Title;
    }
}

/// <summary>
/// Generic group data model.
/// </summary>
public class SampleDataGroup
{
    public SampleDataGroup(String uniqueId, String title, String subtitle, String imagePath, String description)
    {
        this.UniqueId = uniqueId;
        this.Title = title;
        this.Subtitle = subtitle;
        this.Description = description;
        this.ImagePath = imagePath;
        this.Items = new ObservableCollection<SampleDataItem>();
    }

    public string UniqueId { get; private set; }
    public string Title { get; private set; }
    public string Subtitle { get; private set; }
    public string Description { get; private set; }
    public string ImagePath { get; private set; }
    public ObservableCollection<SampleDataItem> Items { get; private set; }

    public override string ToString()
    {
        return this.Title;
    }
}

/// <summary>
/// Creates a collection of groups and items with content read from a static json file.
/// 
/// SampleDataSource initializes with data read from a static json file included in the 
/// project.  This provides sample data at both design-time and run-time.
/// </summary>
public sealed class SampleDataSource
{
    private static SampleDataSource _sampleDataSource = new SampleDataSource();

    private ObservableCollection<SampleDataGroup> _groups = new ObservableCollection<SampleDataGroup>();
    private ObservableCollection<SamplePoemItem> _poems = new ObservableCollection<SamplePoemItem>();
    public ObservableCollection<SampleDataGroup> Groups
    {
        get { return this._groups; }
    }
    public ObservableCollection<SamplePoemItem> Poems
    {
        get { return this._poems; }
    }

    public static async Task<IEnumerable<SampleDataGroup>> GetGroupsAsync()
    {
        await _sampleDataSource.GetSampleDataAsync();

        return _sampleDataSource.Groups;
    }

    public static async Task<IEnumerable<SamplePoemItem>> GetPoemsAsync()
    {
        await _sampleDataSource.GetSampleDataAsync();

        return _sampleDataSource.Poems;


    }
    public static async Task<SampleDataGroup> GetGroupAsync(string uniqueId)
    {
        await _sampleDataSource.GetSampleDataAsync();
        // Simple linear search is acceptable for small data sets
        var matches = _sampleDataSource.Groups.Where((group) => group.UniqueId.Equals(uniqueId));
        if (matches.Count() == 1) return matches.First();
        return null;
    }

    public static async Task<SampleDataItem> GetItemAsync(string uniqueId)
    {
        await _sampleDataSource.GetSampleDataAsync();
        // Simple linear search is acceptable for small data sets
        var matches = _sampleDataSource.Groups.SelectMany(group => group.Items).Where((item) => item.UniqueId.Equals(uniqueId));
        if (matches.Count() == 1) return matches.First();
        return null;
    }

    public static async Task<SamplePoemItem> GetPoemAsync(string poemid)
    {
        await _sampleDataSource.GetSampleDataAsync();
        //Simple linear search for Poem data sets
        //  var matches = _sampleDataSource.Poems.SelectMany(item => item.PoemTitle).Where((poemtitle) => poemid.Equals(poemid));
        var matches = _sampleDataSource.Poems.Where((poemtitle) => poemid.Equals(poemid));
        if (matches.Count() == 1) return matches.First();
        return null;


    }

    private async Task GetSampleDataAsync()
    {
        if (this._groups.Count != 0)
            return;

        Uri dataUri = new Uri("ms-appx:///DataModel/SampleData.json");

        StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(dataUri);
        string jsonText = await FileIO.ReadTextAsync(file);
        JsonObject jsonObject = JsonObject.Parse(jsonText);
        JsonArray jsonArray = jsonObject["Groups"].GetArray();

        foreach (JsonValue groupValue in jsonArray)
        {
            JsonObject groupObject = groupValue.GetObject();
            SampleDataGroup group = new SampleDataGroup(groupObject["UniqueId"].GetString(),
                                                        groupObject["Title"].GetString(),
                                                        groupObject["Subtitle"].GetString(),
                                                        groupObject["ImagePath"].GetString(),
                                                        groupObject["Description"].GetString());

            foreach (JsonValue itemValue in groupObject["Items"].GetArray())
            {
                JsonObject itemObject = itemValue.GetObject();
                group.Items.Add(new SampleDataItem(itemObject["UniqueId"].GetString(),
                                                   itemObject["Title"].GetString(),
                                                   itemObject["Subtitle"].GetString(),
                                                   itemObject["ImagePath"].GetString(),
                                                   itemObject["Description"].GetString(),
                                                   itemObject["Content"].GetString()));

                foreach (JsonValue poemValue in itemObject["Poems"].GetArray())
                {
                    JsonObject poemObject = poemValue.GetObject();
                 Poems.Add(new SamplePoemItem(poemObject["PoemId"].GetString(),
                        poemObject["PoemTitle"].GetString(),
                        poemObject["PoemMean"].GetString()));
                }
            }
            this.Groups.Add(group);
        }
    }
}
<Grid x:Name="LayoutRoot">
    <Grid.ChildrenTransitions>
        <TransitionCollection>
            <EntranceThemeTransition/>
        </TransitionCollection>
    </Grid.ChildrenTransitions>

    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>

    <!-- Title Panel -->
    <StackPanel Grid.Row="0" Margin="19,0,0,0">
        <TextBlock x:Uid="Header" Text="application name" Style="{ThemeResource TitleTextBlockStyle}" Margin="0,12,0,0" />
        <TextBlock d:DataContext="{Binding Groups[0].Items[0], Source={d:DesignData Source=../TrialAPP.Shared/DataModel/SampleData.json, Type=data:SampleDataSource}}" Text="{Binding Title}" Style="{ThemeResource HeaderTextBlockStyle}" Margin="0,-6.5,0,26.5" CharacterSpacing="{ThemeResource PivotHeaderItemCharacterSpacing}"/>
    </StackPanel>

    <!--TODO: Content should be placed within the following grid 
              to show details for the current item -->
    <Grid Grid.Row="1" x:Name="ContentRoot" Margin="19,9.5,19,0">
        <ListView
        x:Name="PoemListView"
        AutomationProperties.AutomationId="PoemListView"
        AutomationProperties.Name="Poems In Item"
        TabIndex="1"
        Grid.Row="1"
        ItemsSource="{Binding Poems}"
        IsItemClickEnabled="True"
        ItemClick="PoemView_PoemClick"
        SelectionMode="None"
        IsSwipeEnabled="False"
        Margin="19,0,0,0">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>

                        <StackPanel Grid.Column="1" VerticalAlignment="Top" Margin="15,0,-295.833,-229" Height="312">
                            <TextBlock Text="{Binding PoemId}" Style="{ThemeResource ListViewItemTextBlockStyle}"/>
                            <TextBlock Text="{Binding PoemTitle}" Style="{ThemeResource ListViewItemContentTextBlockStyle}" Foreground="{ThemeResource PhoneMidBrush}"/>
                            <TextBlock Text="{Binding PoemMean}" Style="{ThemeResource ListViewItemSubheaderTextBlockStyle}"/>
                        </StackPanel>
                    </Grid>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </Grid>
</Grid>
}

<Grid x:Name="LayoutRoot">
    <Grid.ChildrenTransitions>
        <TransitionCollection>
            <EntranceThemeTransition/>
        </TransitionCollection>
    </Grid.ChildrenTransitions>

    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>

    <!-- Title Panel -->
    <StackPanel Grid.Row="0" Margin="19,0,0,0">
        <TextBlock x:Uid="Header" Text="application name" Style="{ThemeResource TitleTextBlockStyle}" Margin="0,12,0,0" />
        <TextBlock d:DataContext="{Binding Groups[0].Items[0], Source={d:DesignData Source=../TrialAPP.Shared/DataModel/SampleData.json, Type=data:SampleDataSource}}" Text="{Binding Title}" Style="{ThemeResource HeaderTextBlockStyle}" Margin="0,-6.5,0,26.5" CharacterSpacing="{ThemeResource PivotHeaderItemCharacterSpacing}"/>
    </StackPanel>

    <!--TODO: Content should be placed within the following grid 
              to show details for the current item -->
    <Grid Grid.Row="1" x:Name="ContentRoot" Margin="19,9.5,19,0">
        <ListView
        x:Name="PoemListView"
        AutomationProperties.AutomationId="PoemListView"
        AutomationProperties.Name="Poems In Item"
        TabIndex="1"
        Grid.Row="1"
        ItemsSource="{Binding Poems}"
        IsItemClickEnabled="True"
        ItemClick="PoemView_PoemClick"
        SelectionMode="None"
        IsSwipeEnabled="False"
        Margin="19,0,0,0">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>

                        <StackPanel Grid.Column="1" VerticalAlignment="Top" Margin="15,0,-295.833,-229" Height="312">
                            <TextBlock Text="{Binding PoemId}" Style="{ThemeResource ListViewItemTextBlockStyle}"/>
                            <TextBlock Text="{Binding PoemTitle}" Style="{ThemeResource ListViewItemContentTextBlockStyle}" Foreground="{ThemeResource PhoneMidBrush}"/>
                            <TextBlock Text="{Binding PoemMean}" Style="{ThemeResource ListViewItemSubheaderTextBlockStyle}"/>
                        </StackPanel>
                    </Grid>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </Grid>
</Grid>
这是ItemPage.Xaml,我在这里显示数据

<Grid x:Name="LayoutRoot">
    <Grid.ChildrenTransitions>
        <TransitionCollection>
            <EntranceThemeTransition/>
        </TransitionCollection>
    </Grid.ChildrenTransitions>

    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>

    <!-- Title Panel -->
    <StackPanel Grid.Row="0" Margin="19,0,0,0">
        <TextBlock x:Uid="Header" Text="application name" Style="{ThemeResource TitleTextBlockStyle}" Margin="0,12,0,0" />
        <TextBlock d:DataContext="{Binding Groups[0].Items[0], Source={d:DesignData Source=../TrialAPP.Shared/DataModel/SampleData.json, Type=data:SampleDataSource}}" Text="{Binding Title}" Style="{ThemeResource HeaderTextBlockStyle}" Margin="0,-6.5,0,26.5" CharacterSpacing="{ThemeResource PivotHeaderItemCharacterSpacing}"/>
    </StackPanel>

    <!--TODO: Content should be placed within the following grid 
              to show details for the current item -->
    <Grid Grid.Row="1" x:Name="ContentRoot" Margin="19,9.5,19,0">
        <ListView
        x:Name="PoemListView"
        AutomationProperties.AutomationId="PoemListView"
        AutomationProperties.Name="Poems In Item"
        TabIndex="1"
        Grid.Row="1"
        ItemsSource="{Binding Poems}"
        IsItemClickEnabled="True"
        ItemClick="PoemView_PoemClick"
        SelectionMode="None"
        IsSwipeEnabled="False"
        Margin="19,0,0,0">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>

                        <StackPanel Grid.Column="1" VerticalAlignment="Top" Margin="15,0,-295.833,-229" Height="312">
                            <TextBlock Text="{Binding PoemId}" Style="{ThemeResource ListViewItemTextBlockStyle}"/>
                            <TextBlock Text="{Binding PoemTitle}" Style="{ThemeResource ListViewItemContentTextBlockStyle}" Foreground="{ThemeResource PhoneMidBrush}"/>
                            <TextBlock Text="{Binding PoemMean}" Style="{ThemeResource ListViewItemSubheaderTextBlockStyle}"/>
                        </StackPanel>
                    </Grid>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </Grid>
</Grid>

<Grid x:Name="LayoutRoot">
    <Grid.ChildrenTransitions>
        <TransitionCollection>
            <EntranceThemeTransition/>
        </TransitionCollection>
    </Grid.ChildrenTransitions>

    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>

    <!-- Title Panel -->
    <StackPanel Grid.Row="0" Margin="19,0,0,0">
        <TextBlock x:Uid="Header" Text="application name" Style="{ThemeResource TitleTextBlockStyle}" Margin="0,12,0,0" />
        <TextBlock d:DataContext="{Binding Groups[0].Items[0], Source={d:DesignData Source=../TrialAPP.Shared/DataModel/SampleData.json, Type=data:SampleDataSource}}" Text="{Binding Title}" Style="{ThemeResource HeaderTextBlockStyle}" Margin="0,-6.5,0,26.5" CharacterSpacing="{ThemeResource PivotHeaderItemCharacterSpacing}"/>
    </StackPanel>

    <!--TODO: Content should be placed within the following grid 
              to show details for the current item -->
    <Grid Grid.Row="1" x:Name="ContentRoot" Margin="19,9.5,19,0">
        <ListView
        x:Name="PoemListView"
        AutomationProperties.AutomationId="PoemListView"
        AutomationProperties.Name="Poems In Item"
        TabIndex="1"
        Grid.Row="1"
        ItemsSource="{Binding Poems}"
        IsItemClickEnabled="True"
        ItemClick="PoemView_PoemClick"
        SelectionMode="None"
        IsSwipeEnabled="False"
        Margin="19,0,0,0">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>

                        <StackPanel Grid.Column="1" VerticalAlignment="Top" Margin="15,0,-295.833,-229" Height="312">
                            <TextBlock Text="{Binding PoemId}" Style="{ThemeResource ListViewItemTextBlockStyle}"/>
                            <TextBlock Text="{Binding PoemTitle}" Style="{ThemeResource ListViewItemContentTextBlockStyle}" Foreground="{ThemeResource PhoneMidBrush}"/>
                            <TextBlock Text="{Binding PoemMean}" Style="{ThemeResource ListViewItemSubheaderTextBlockStyle}"/>
                        </StackPanel>
                    </Grid>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </Grid>
</Grid>
问题是ItemPage.Xaml在预览中显示得非常好。但是当我部署应用程序时,我在ItemPage.Xaml中没有得到任何内容

<Grid x:Name="LayoutRoot">
    <Grid.ChildrenTransitions>
        <TransitionCollection>
            <EntranceThemeTransition/>
        </TransitionCollection>
    </Grid.ChildrenTransitions>

    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>

    <!-- Title Panel -->
    <StackPanel Grid.Row="0" Margin="19,0,0,0">
        <TextBlock x:Uid="Header" Text="application name" Style="{ThemeResource TitleTextBlockStyle}" Margin="0,12,0,0" />
        <TextBlock d:DataContext="{Binding Groups[0].Items[0], Source={d:DesignData Source=../TrialAPP.Shared/DataModel/SampleData.json, Type=data:SampleDataSource}}" Text="{Binding Title}" Style="{ThemeResource HeaderTextBlockStyle}" Margin="0,-6.5,0,26.5" CharacterSpacing="{ThemeResource PivotHeaderItemCharacterSpacing}"/>
    </StackPanel>

    <!--TODO: Content should be placed within the following grid 
              to show details for the current item -->
    <Grid Grid.Row="1" x:Name="ContentRoot" Margin="19,9.5,19,0">
        <ListView
        x:Name="PoemListView"
        AutomationProperties.AutomationId="PoemListView"
        AutomationProperties.Name="Poems In Item"
        TabIndex="1"
        Grid.Row="1"
        ItemsSource="{Binding Poems}"
        IsItemClickEnabled="True"
        ItemClick="PoemView_PoemClick"
        SelectionMode="None"
        IsSwipeEnabled="False"
        Margin="19,0,0,0">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>

                        <StackPanel Grid.Column="1" VerticalAlignment="Top" Margin="15,0,-295.833,-229" Height="312">
                            <TextBlock Text="{Binding PoemId}" Style="{ThemeResource ListViewItemTextBlockStyle}"/>
                            <TextBlock Text="{Binding PoemTitle}" Style="{ThemeResource ListViewItemContentTextBlockStyle}" Foreground="{ThemeResource PhoneMidBrush}"/>
                            <TextBlock Text="{Binding PoemMean}" Style="{ThemeResource ListViewItemSubheaderTextBlockStyle}"/>
                        </StackPanel>
                    </Grid>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </Grid>
</Grid>

我做错了什么?在生成期间,我没有收到任何错误/警告。

请在中删除Grid.Row=1并给出结果。即使在删除Grid.Row=1后,结果也没有变化。中的Row=1是否与ItemPage.xaml背后的代码有关?私有异步void NavigationHelper\u LoadStateobject发送方,LoadStateEventArgs e{var item=Wait SampleDataSource.GetItemAsyncstringe.NavigationParameter;this.DefaultViewModel[item]=item;}请使用LongListSelector而不是ListView。您推荐LongListSelector的具体原因是什么?除了ItemPage.Xaml之外,ListView在我的应用程序中运行得非常好。
<Grid x:Name="LayoutRoot">
    <Grid.ChildrenTransitions>
        <TransitionCollection>
            <EntranceThemeTransition/>
        </TransitionCollection>
    </Grid.ChildrenTransitions>

    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>

    <!-- Title Panel -->
    <StackPanel Grid.Row="0" Margin="19,0,0,0">
        <TextBlock x:Uid="Header" Text="application name" Style="{ThemeResource TitleTextBlockStyle}" Margin="0,12,0,0" />
        <TextBlock d:DataContext="{Binding Groups[0].Items[0], Source={d:DesignData Source=../TrialAPP.Shared/DataModel/SampleData.json, Type=data:SampleDataSource}}" Text="{Binding Title}" Style="{ThemeResource HeaderTextBlockStyle}" Margin="0,-6.5,0,26.5" CharacterSpacing="{ThemeResource PivotHeaderItemCharacterSpacing}"/>
    </StackPanel>

    <!--TODO: Content should be placed within the following grid 
              to show details for the current item -->
    <Grid Grid.Row="1" x:Name="ContentRoot" Margin="19,9.5,19,0">
        <ListView
        x:Name="PoemListView"
        AutomationProperties.AutomationId="PoemListView"
        AutomationProperties.Name="Poems In Item"
        TabIndex="1"
        Grid.Row="1"
        ItemsSource="{Binding Poems}"
        IsItemClickEnabled="True"
        ItemClick="PoemView_PoemClick"
        SelectionMode="None"
        IsSwipeEnabled="False"
        Margin="19,0,0,0">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>

                        <StackPanel Grid.Column="1" VerticalAlignment="Top" Margin="15,0,-295.833,-229" Height="312">
                            <TextBlock Text="{Binding PoemId}" Style="{ThemeResource ListViewItemTextBlockStyle}"/>
                            <TextBlock Text="{Binding PoemTitle}" Style="{ThemeResource ListViewItemContentTextBlockStyle}" Foreground="{ThemeResource PhoneMidBrush}"/>
                            <TextBlock Text="{Binding PoemMean}" Style="{ThemeResource ListViewItemSubheaderTextBlockStyle}"/>
                        </StackPanel>
                    </Grid>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </Grid>
</Grid>