繁体   English   中英

为什么当我切换语义缩放时,它不会导航到该部分?

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM