[英]Why when I switch my semantic zoom, it does not navigate to the section?
我的語義縮放有些奇怪。 我有兩個部分:
當我設置ZoomOut時,分組是可以的,這是圖像:
但是,例如,如果我選擇第二個選項,語義縮放不會導航我到單擊的項目。
以下是我的計划中最重要的部分。
<!-- from resources -->
<CollectionViewSource
x:Name="groupedItemsViewSource"
Source="{Binding Groups}"
IsSourceGrouped="False">
...
<!-- Horizontal scrolling grid used in most view states -->
<SemanticZoom x:Name="semanticZoomControl" Grid.Row="1" >
<SemanticZoom.ZoomedInView>
<ListView x:Name="itemGridView" SelectionMode="None" IsItemClickEnabled="False"
ScrollViewer.VerticalScrollBarVisibility="Disabled"
ScrollViewer.VerticalScrollMode="Disabled"
ScrollViewer.HorizontalScrollBarVisibility="Auto"
ScrollViewer.HorizontalScrollMode="Auto"
Margin="0,-3,0,0"
Padding="116,0,40,46"
ItemTemplateSelector="{StaticResource StartItemSelector}"
ItemsSource="{Binding Source={StaticResource groupedItemsViewSource}}"
ItemContainerStyle="{StaticResource ListViewItemStyleFlat}">
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ListView.ItemsPanel>
</ListView>
</SemanticZoom.ZoomedInView>
<SemanticZoom.ZoomedOutView>
<ListView x:Name="groupGridView" CanDragItems="False"
CanReorderItems="False" SelectionMode="None" IsItemClickEnabled="True"
ScrollViewer.HorizontalScrollBarVisibility="Auto"
ScrollViewer.HorizontalScrollMode="Auto"
ScrollViewer.VerticalScrollBarVisibility="Disabled"
ScrollViewer.VerticalScrollMode="Disabled"
ItemContainerStyle="{StaticResource ListViewItemStyleSimple}"
ItemsSource="{Binding Source={StaticResource groupedItemsViewSource}}"
ItemTemplateSelector="{StaticResource ZoomedOutSelector}">
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" Height="330"
HorizontalAlignment="Left" VerticalAlignment="Top" />
</ItemsPanelTemplate>
</ListView.ItemsPanel>
</ListView>
這可能是什么原因發生的?
如果您感覺更舒適,可以從SkyDrive下載該項目: http : //sdrv.ms/Ma0LmE
您需要在代碼隱藏中設置Zoomed Out GridView的ItemsSource
groupGridView.ItemsSource = groupedItemsViewSource.View.CollectionGroups;
您很可能需要更新該網格的模板,以附加“組”。 在綁定之前。
你的ItemTemplateSelector也將停止工作,它將傳遞一個DependencyObject而不是你的綁定組。 您可以將對象強制轉換為ICollectionViewGroup,它具有可以強制轉換為模型對象的Group屬性等。
這對屁股來說都很痛苦,但我現在找不到更好的方法。
我的情況有所不同,但我決定在這里分享,希望有人會發現它有用。 在我的應用程序中,我必須有兩個不同的數據源用於語義縮放的放大/縮小視圖。 當然,這打破了兩者之間的聯系,所以我不能做@Nigel上面提到的以及在一般情況下會起作用的東西。 相反,我必須自己處理滾動。
所以,我為視圖更改事件添加了一個事件處理程序:
<SemanticZoom ViewChangeStarted="OnSemanticZoomViewChangeStarted">
...
</SemanticZoom>
然后我在codebehind中定義它:
private void OnSemanticZoomViewChangeStarted(object sender, SemanticZoomViewChangedEventArgs e)
{
// only interested in zoomed out->zoomed in transitions
if (e.IsSourceZoomedInView)
{
return;
}
// get the selected group
MyItemGroup selectedGroup = e.SourceItem.Item as MyItemGroup;
// identify the selected group in the zoomed in data source (here I do it by its name, YMMV)
ObservableCollection<MyItemGroup> myItemGroups = this.DefaultViewModel["GroupedItems"] as ObservableCollection<MyItemGroup>;
MyItemGroup myGroup = myItemGroups.First<MyItemGroup>((g) => { return g.Name == selectedGroup.Name; });
// workaround: need to reset the scroll position first, otherwise ScrollIntoView won't work
SemanticZoomLocation zoomloc = new SemanticZoomLocation();
zoomloc.Bounds = new Windows.Foundation.Rect(0, 0, 1, 1);
zoomloc.Item = myItemGroups[0];
zoomedInGridView.MakeVisible(zoomloc);
// now we can scroll to the selected group in the zoomed in view
zoomedInGridView.ScrollIntoView(myGroup, ScrollIntoViewAlignment.Leading);
}
正如您所看到的,黑客是首先需要重繞gridview以使ScrollIntoView
正常工作。 我想這只是微軟“設計”決策中的另一個......:P
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.