【问题标题】:Semantic Zoom doesn't work in Windows 8 app语义缩放在 Windows 8 应用程序中不起作用
【发布时间】:2014-10-06 14:44:01
【问题描述】:

我正在尝试在我的 Windows 8 应用程序中使用 SemanticZoom,但它似乎不起作用。

我在这里做错了吗? 我尝试了几乎所有我认为可行但徒劳的方法:删除了行定义,删除了样式,删除了模板,但仍然无法正常工作...

<Grid Style="{StaticResource LayoutRootStyle}">
    <Grid.RowDefinitions>
        <RowDefinition Height="140"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>

    <SemanticZoom Grid.RowSpan="2">            
        <SemanticZoom.ZoomedInView>
             <GridView x:Name="itemGridView"
                      AutomationProperties.AutomationId="ItemGridView"
                      AutomationProperties.Name="Grouped Items"
                      Padding="116,137,40,46"
                      ItemsSource="{Binding Source={StaticResource groupedItemsViewSource}}"
                      SelectionMode="None"
                      IsSwipeEnabled="True"
                      IsItemClickEnabled="True"
                      ItemTemplate="{StaticResource GridViewItemTemplateZoomIn}"
                      ItemsPanel="{StaticResource GridViewItemsPanelTemplate}"
                      helpers:ItemClickCommand.Command="{Binding ServiceClickCommand}">
                <GridView.GroupStyle>
                    <GroupStyle HidesIfEmpty="True">
                        <GroupStyle.HeaderTemplate>
                            <DataTemplate>
                                <Grid Margin="1,0,10,6">
                                    <Button AutomationProperties.Name="Group Title"
                                            Style="{StaticResource TextPrimaryButtonStyle}">
                                        <StackPanel Orientation="Horizontal">
                                            <TextBlock Text="{Binding Name}"
                                                       Margin="3,-7,10,10"
                                                       Style="{StaticResource GroupHeaderTextStyle}" />
                                            <TextBlock Text="{StaticResource ChevronGlyph}"
                                                       FontFamily="Segoe UI Symbol"
                                                       Margin="0,-7,0,10"
                                                       Style="{StaticResource GroupHeaderTextStyle}" />
                                        </StackPanel>
                                    </Button>
                                </Grid>
                            </DataTemplate>
                        </GroupStyle.HeaderTemplate>
                        <GroupStyle.Panel>
                            <ItemsPanelTemplate>
                                <VariableSizedWrapGrid Orientation="Vertical"
                                                       Margin="0,0,80,0" />
                            </ItemsPanelTemplate>
                        </GroupStyle.Panel>
                    </GroupStyle>
                </GridView.GroupStyle>
            </GridView>
        </SemanticZoom.ZoomedInView>
        <SemanticZoom.ZoomedOutView>
            <GridView x:Name="itemZoomOutGridView"
                      ScrollViewer.IsHorizontalScrollChainingEnabled="False"
                      AutomationProperties.AutomationId="ItemGridView"
                      AutomationProperties.Name="Grouped Items"
                      Padding="116,175,40,46"
                      SelectionMode="None"
                      IsSwipeEnabled="True"
                      IsItemClickEnabled="True"
                      ItemTemplate="{StaticResource GridViewItemTemplateZoomOut}"
                      ItemsPanel="{StaticResource GridViewItemsPanelTemplate}"
                      ItemsSource="{Binding ServiceCategories}">
            </GridView>
        </SemanticZoom.ZoomedOutView>
    </SemanticZoom>

谢谢你:)

【问题讨论】:

  • 什么不起作用?是不是没有出现?它会缩放吗? IE。放大的视图会消失吗?你是用鼠标还是在设备上测试它?您是否正在使用模拟器来测试触摸控制?必须提供更多关于什么不起作用的信息,而不仅仅是“它不起作用”。
  • @NateDiamond 对不起,我没有指定 ^^ 显示语义缩放,它通常工作得很好但是当我点击 ZoomedOut 上的一个项目时,它只是回到 ZoomedIn 视图无需转到所选项目...
  • @NateDiamond 我正在使用 MS VS 2013 模拟器来测试我的应用程序,但如果我在本地 Windows 8 上部署应用程序,结果是一样的。

标签: xaml windows-store-apps winrt-xaml windows-applications semantic-zoom


【解决方案1】:

如果我正确理解您的问题,semanticView 本身就可以工作(您可以放大和缩小)。但是当您放大 GridView 时,项目是相同的,并且不会根据您选择的 ZoomedOutView GridView 项目而改变。

但是对于您的 XAML,我认为这是正常行为,因为当您选择一个类别时,您在 zoomedInView 中的 gridview 上的绑定不会改变。

ItemsSource="{Binding Source={StaticResource groupedItemsViewSource}}"

我的第一个建议是将 ItemsSource 绑定到 ViewModel 中的列表,而不是使用 staticRessource。

其次,您可以通过这种方式更改 SemanticView:

<SemanticZoom Grid.RowSpan="2" ViewChangeStarted="SemanticZoomChanged" >

然后在你后面的代码中添加:

private void SemanticZoomChanged(object sender, SemanticZoomViewChangedEventArgs e)
{
   // First we check that we are going from ZoomedOut to ZoomedIn
   if (e.IsSourceZoomedInView == false)
   {
      // I call a method in my ViewModel giving the chosen category in parameter
      DefaultViewModel.OnSelectedCategoryChanged(e.SourceItem.Item.ToString());
   }
}

使用 MVVM 我知道在代码隐藏中有代码很难看,但这并不多,我们在 ViewModel 中调用一个方法来执行逻辑,所以它仍然遵循 MVVM 设计模式。

最后我们在 ViewModel 中添加一个函数,该函数将更改 ZoomedInView 的 ItemsSource

OnSelectedCategoryChanged(string chosenCategory)
{
    // Here change the value of your groupedItemsViewSource list
    GroupedItemsViewSource = ....;
}

现在它应该可以按您的意愿工作了。

【讨论】:

  • 感谢您的回答,我找到了一种方法来做我需要的事情! :)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-11-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多