绑定GridView,缺少什么?

时间:2013-01-01 22:56:49

标签: vb.net xaml gridview binding windows-8

(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

(这是在异步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

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

0 个答案:

没有答案