【问题标题】:Why when I switch my semantic zoom, it does not navigate to the section?为什么当我切换语义缩放时,它没有导航到该部分?
【发布时间】:2012-07-26 16:10:20
【问题描述】:

我的语义缩放有些奇怪。我有两个部分:

当我设置 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

【问题讨论】:

    标签: c# xaml windows-8 microsoft-metro semantic-zoom


    【解决方案1】:

    需要在codebehind中设置Zoomed Out GridView的ItemsSource,如

    groupGridView.ItemsSource = groupedItemsViewSource.View.CollectionGroups;
    

    您很可能需要更新该网格的模板,以附加“组”。在绑定之前。

    您的 ItemTemplateSelector 也将停止工作,它将传递一个 DependencyObject 而不是您的绑定组。您可以将对象转换为具有 Group 属性的 ICollectionViewGroup,您可以将其转换为模型对象等。

    这很痛苦,但我目前找不到更好的方法。

    【讨论】:

      【解决方案2】:

      我的情况有些不同,但我决定在这里分享,希望有人会觉得它有用。在我的应用程序中,我必须有两个不同的数据源用于语义缩放的放大/缩小视图。当然,这打破了两者之间的联系,所以我不能做上面@Nigel 建议的事情以及在一般情况下会起作用的事情。相反,我必须自己处理滚动。

      所以,我为视图更改事件添加了一个事件处理程序:

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

      然后我在代码隐藏中定义了它:

      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);
      }
      

      如您所见,hack 是首先需要重绕 gridview 以使 ScrollIntoView 正常工作。我想这只是微软的另一个“设计”决定......:P

      【讨论】:

      • 你好! visualItemGroups 这里是什么?我被困在那条线上,我感觉很无能为力。我有一个场景,其中放大和缩小视图的来源相同,但不能使用分组的 CollectionViewSource。
      • 嗯,这似乎是一个错字,应该是myItemGroups。我也会在 sn-p 中更正它。
      猜你喜欢
      • 1970-01-01
      • 2017-08-22
      • 2013-01-10
      • 1970-01-01
      • 1970-01-01
      • 2019-06-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多