0

(Windows 8)我试图让我的 GridView 绑定到导航到页面时加载的一些分组对象。基本上我想要的是在其他对象仍在加载时显示这些加载的对象。

以下代码显示网格仅显示所有已加载的项目:

Dim myItems As New ObservableCollection(Of SearchResultItem)
Dim group As New SearchResultGroup With {.Title = "Title"}
group.Items = myItems
' Loading code here
DefaultViewModel("Groups") = New ObservableCollection(Of SearchResultGroup)({group})

但是,以下内容根本没有显示任何内容:

Dim myItems As New ObservableCollection(Of SearchResultItem)
Dim group As New SearchResultGroup With {.Title = "Title"}
group.Items = myItems
DefaultViewModel("Groups") = New ObservableCollection(Of SearchResultGroup)({group})
' Loading code here

(这是在 async LoadState 函数下)

这是页面的代码:

<common:LayoutAwarePage DataContext={Binding DefaultViewModel, RelativeSource={RelativeSource Self}} ... >
    <Page.Resources>
        <CollectionViewSource
            x:Name="groupedItemsViewSource"
            Source="{Binding Groups}"
            IsSourceGrouped="true"
            ItemsPath="Items"/>
        ...
    </Page.Resources>
    <Grid Style="{StaticResource LayoutRootStyle}">
        ....
        <GridView
            x:Name="itemGridView"
            AutomationProperties.AutomationId="ItemGridView"
            AutomationProperties.Name="Grouped Items"
            Grid.RowSpan="2"
            Padding="116,137,40,46"
            ItemsSource="{Binding Source={StaticResource groupedItemsViewSource},Mode=TwoWay}"
            ItemTemplate="{StaticResource ResultTemplate}"
            SelectionMode="None"
            IsSwipeEnabled="false"
            IsItemClickEnabled="True">
            ...

这是我使用的自定义项目和组类:

Public Class SearchResultGroup
    Inherits BindableBase

    Public Sub New() ...
    Private _Title As String
    Property Title As String ...
    Private _Items As ObservableCollection(Of SearchResultItem)
    Property Items As ObservableCollection(Of SearchResultItem) ...
End Class

Public Class SearchResultItem
    Inherits BindableBase

    Private _Title As String       
    Property Title As String ...
    Private _Title2 As String
    Property Title2 As String ...
    Private _Subtitle As String
    Property Subtitle As String
End Class

(只是在这里删掉一些不必要的代码......将根据需要进行编辑)

4

0 回答 0