简体   繁体   English

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

[英]Why when I switch my semantic zoom, it does not navigate to the section?

Something is strange with my semantic zoom. 我的语义缩放有些奇怪。 I have two sections in it: 我有两个部分:

在此输入图像描述在此输入图像描述

And when I set the the ZoomOut, the grouping is okay, here is the image: 当我设置ZoomOut时,分组是可以的,这是图像:

在此输入图像描述

But for example if I choose the second option, semantic zoom does not navigate me to the item clicked. 但是,例如,如果我选择第二个选项,语义缩放不会导航我到单击的项目。

Here are the most important parts of my program. 以下是我的计划中最重要的部分。

    <!-- 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>

What could be the reason which is happening this? 这可能是什么原因发生的?

If you feel more confortable, you can download the project from SkyDrive: http://sdrv.ms/Ma0LmE 如果您感觉更舒适,可以从SkyDrive下载该项目: http//sdrv.ms/Ma0LmE

You need to set the ItemsSource of the Zoomed Out GridView in the codebehind like 您需要在代码隐藏中设置Zoomed Out GridView的ItemsSource

groupGridView.ItemsSource = groupedItemsViewSource.View.CollectionGroups;

You'll most likely need to update your templates for that Grid, to append a "Group." 您很可能需要更新该网格的模板,以附加“组”。 before your bindings. 在绑定之前。

Your ItemTemplateSelector will also stop working at it will be passed a DependencyObject rather than your bound group. 你的ItemTemplateSelector也将停止工作,它将传递一个DependencyObject而不是你的绑定组。 You can cast the object to ICollectionViewGroup which has a Group property that you can cast to your model object etc. 您可以将对象强制转换为ICollectionViewGroup,它具有可以强制转换为模型对象的Group属性等。

It's all a pain in the ass but I can't find a better way at the moment. 这对屁股来说都很痛苦,但我现在找不到更好的方法。

My case was somewhat different but I decided to share it here, hope someone will find it useful. 我的情况有所不同,但我决定在这里分享,希望有人会发现它有用。 In my app I had to have two different datasources for the zoomed in/out views of the semantic zoom. 在我的应用程序中,我必须有两个不同的数据源用于语义缩放的放大/缩小视图。 This, of course, broke the link between the two, so I couldn't do what @Nigel suggested above and what would work in the general case. 当然,这打破了两者之间的联系,所以我不能做@Nigel上面提到的以及在一般情况下会起作用的东西。 Instead, I had to handle scrolling myself. 相反,我必须自己处理滚动。

So, I added an event handler for the view change event: 所以,我为视图更改事件添加了一个事件处理程序:

<SemanticZoom ViewChangeStarted="OnSemanticZoomViewChangeStarted">
...
</SemanticZoom>

Then I defined it in the codebehind: 然后我在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);
}

As you can see, the hack is that the gridview first needs to be rewound for the ScrollIntoView to work properly. 正如您所看到的,黑客是首先需要重绕gridview以使ScrollIntoView正常工作。 I suppose this is just another of Microsoft's "by design" decisions... :P 我想这只是微软“设计”决策中的另一个......:P

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 语义缩放-点击项目以导航到特定页面 - Semantic zoom - tap item to navigate to specific page 为什么我的开关在有单引号时工作? - Why does my switch work when it has single quotes? 使用MS Chart Controls缩放时,为什么我的X轴标签会消失? - Why do my X-Axes labels disappear when I zoom using MS Chart Controls? 从分支切换到母版时,为什么项目中的文件没有更改? - Why aren't my files in my project changing when I switch from a branch to master? 为什么自动缩放/滚动不适用于我的图表? - Why does auto Zoom/Scroll not work for my Chart? 从应用程序中的一个页面导航到另一个页面时,为什么会丢失导航返回条目? - Why am I losing the navigation back entry when I navigate from one of the pages to another page in my application? 如何在组合的语义缩放ListView上显示文本? - How do I get Text to Display on a grouped Semantic Zoom ListView? 为什么第二次导航到ViewModel时未调用Init()方法? - Why Init() method is not called when I navigate to the ViewModel second time? 为什么我的GridView会退出编辑模式? - Why does my GridView switch out of Edit mode? 为什么GC在我引用它时会收集我的对象? - Why does GC collects my object when I have a reference to it?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM