4

私のセマンティックズームで何かがおかしいです。私はそれに2つのセクションがあります:

ここに画像の説明を入力 ここに画像の説明を入力

そして、ズームアウトを設定すると、グループ化は問題ありません。画像は次のとおりです。

ここに画像の説明を入力

しかし、たとえば 2 番目のオプションを選択すると、セマンティック ズームはクリックされた項目に移動しません。

これが私のプログラムの最も重要な部分です。

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

4

2 に答える 2

11

次のように分離コードで Zoomed Out GridView の ItemsSource を設定する必要があります

groupGridView.ItemsSource = groupedItemsViewSource.View.CollectionGroups;

「グループ」を追加するには、おそらくそのグリッドのテンプレートを更新する必要があります。あなたのバインディングの前に。

ItemTemplateSelector も動作を停止し、バインドされたグループではなく DependencyObject が渡されます。モデル オブジェクトなどにキャストできる Group プロパティを持つ ICollectionViewGroup にオブジェクトをキャストできます。

それはすべてお尻の痛みですが、現時点ではより良い方法を見つけることができません.

于 2012-07-26T21:05:25.000 に答える
7

私のケースは多少異なっていましたが、ここで共有することにしました。私のアプリでは、セマンティック ズームの拡大/縮小表示用に 2 つの異なるデータソースが必要でした。もちろん、これは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);
}

ご覧のとおり、ハックは、ScrollIntoView正しく機能させるためにまずグリッドビューを巻き戻す必要があることです。これは、マイクロソフトの「設計による」決定の 1 つにすぎないと思います... :P

于 2012-10-09T11:36:44.673 に答える