Luk*_*ett 5 xaml winrt-xaml windows-store-apps
为什么此代码会在Windows 8 XAML应用程序中产生错误?
价值不在预期范围内.
XAML:
<SemanticZoom>
<SemanticZoom.ZoomedInView>
<ListView
Style="{StaticResource HorizontalListViewStyle}"
SelectionMode="None"
ScrollViewer.IsHorizontalScrollChainingEnabled="False"
ItemsSource="{Binding BoardItems}"
ItemContainerStyle="{StaticResource ZoomedOutListViewItemContainerStyle}"
...
Run Code Online (Sandbox Code Playgroud)
MVVM代码:
ObservableCollection<WritingBoardModel> boards = new ObservableCollection<WritingBoardModel>();
... // Add item models to boards.
CollectionViewSource v = new CollectionViewSource()
{
Source = boards,
};
this.ViewModel.Add(BoardItemsViewModelKey, v);
Run Code Online (Sandbox Code Playgroud)
如果我跳过CollectionViewSource
并直接将boards
实例添加到我的视图模型中,那么一切正常.
我想我需要使用a CollectionViewSource
才能使一些语义缩放选择行为起作用.
卢克
所以,CollectionViewSource
s很奇怪,你必须绑定它们的方式也很奇怪.举个例子,为了"按书"(样本项目的方式),我发现它实际上必须是StaticResource
这样的:
<Page.Resource>
<CollectionViewSource Source="{Binding Whatev}"
x:Key="WhatevSource"/>
</Page.Resource>
<GridView ItemsSource="{Binding Source={StaticResource WhatevSource}}"/>
Run Code Online (Sandbox Code Playgroud)
请注意,我们没有直接将源设置为CollectionViewSource
,但我们设置的是"无路径" Binding
,基本上使用CollectionViewSource
as DataContext
(只是一种方式来考虑它,实际上技术上并不正确).
这是我能够让它工作的唯一方法,不过我相信你在技术上可以在代码隐藏中ItemsSource
直接设置视图CollectionViewSource
或类似的东西.
希望这有助于编码!
我需要像这样绑定到View
CollectionViewSource 的属性:
CollectionViewSource v = new CollectionViewSource()
{
IsSourceGrouped = false,
Source = boards,
};
this.ViewModel.Add(BoardItemsViewModelKey, v.View);
Run Code Online (Sandbox Code Playgroud)
请注意,这对我的两个ListView
s 和保持它们在SemanticZoom
.
归档时间: |
|
查看次数: |
3987 次 |
最近记录: |