【发布时间】:2015-05-04 06:08:30
【问题描述】:
我遇到了一个奇怪的问题,我绑定到 CollectionViewSource 的 GridView 显示最后一项的错误数据。但实际绑定是正确的。如果我监听 ItemClicked,DataContext 是正确的,UI 只是在 GridView 中显示上一个项目的信息。我的目标是绑定到 CollectionViewSource 中的一组分组数据,但如果我只是直接绑定到 ObservableCollection,我什至会发生这种情况。
这是我的 XAML:
<Page.Resources>
<CollectionViewSource x:Name="CuratedCVS" IsSourceGrouped="True" />
</Page.Resources>
<SemanticZoom Padding="0">
<SemanticZoom.ZoomedInView>
<GridView x:Name="CuratedFeedsList"
ItemsSource="{Binding Source={StaticResource CuratedCVS}}"
ItemTemplate="{StaticResource CuratedFeedItemTemplate}"
SelectedItem="{Binding SelectedFeed, Mode=TwoWay}"
SelectionMode="Single"
IsSwipeEnabled="True"
IsSynchronizedWithCurrentItem="False"
ShowsScrollingPlaceholders="True"
Padding="20,0">
<GridView.GroupStyle>
<GroupStyle HeaderTemplate="{StaticResource CuratedFeedHeaderTemplate}"/>
</GridView.GroupStyle>
</GridView>
</SemanticZoom.ZoomedInView>
<SemanticZoom.ZoomedOutView>
<ListView Background="{Binding SecondaryBackgroundBrush, Source={StaticResource ThemeManager}}"
ItemsSource="{Binding Source={StaticResource CuratedCVS}, Path=CollectionGroups}"
ItemTemplate="{StaticResource CuratedFeedJumpTemplate}"
Padding="0,10">
</ListView>
</SemanticZoom.ZoomedOutView>
</SemanticZoom>
这是我对数据进行分组的代码(似乎可行):
var result =
from f in CuratedFeeds
group f by f.Category into g
orderby g.Key
select g;
CuratedCVS.Source = result;
(其中 CuratedFeeds 是 ObservableCollection)
有人见过这个吗?这只发生在 Windows 8.1 应用程序中。它可以在 Windows Phone 8.1 应用程序中完美运行。
【问题讨论】:
标签: c# gridview windows-runtime windows-8.1