0

Metro アプリで C# と XAML SemanticZoom コントロールとのバインディングを使用しようとしていますが、正直なところ、その方法について途方に暮れています。質問や記事などをつなぎ合わせてこれまでに取得した XAML コードを次に示します。

<SemanticZoom x:Name="boardZoom" Height="626" Margin="10,132,10,0" VerticalAlignment="Top">
        <SemanticZoom.ZoomedInView>

           <GridView IsSwipeEnabled="True" x:Name="ItemsGridView">

                    <GridView.ItemTemplate>

                        <DataTemplate>
                            <StackPanel Orientation="Horizontal" Margin="10,10,0,0" 
                        HorizontalAlignment="Left" Background="White">
                                <TextBlock Text="{Binding Title}" TextWrapping="Wrap" Width="200" Height="300"
                                    FontFamily="Global User Interface" FontSize="40" Foreground="Black"
                           VerticalAlignment="Center"  HorizontalAlignment="Left"/>

                                <Image Source="{Binding Image}" Height="60" Width="60" 
                       VerticalAlignment="Center" Margin="0,0,10,0" Visibility="{Binding isImage}" />

                                <TextBlock Text="{Binding Category}" TextWrapping="Wrap" Width="200"
                                    FontFamily="Global User Interface" Foreground="Black"
                           VerticalAlignment="Center"  HorizontalAlignment="Left"/>
                            </StackPanel>
                        </DataTemplate>

                    </GridView.ItemTemplate>

                </GridView>
            </SemanticZoom.ZoomedInView>

<!--Didn't include SemanticZoom.ZoomedOutView since I'm still trying to get the ZoomedIn one working first-->

        </SemanticZoom>

そして私のC#コード:

        List<PinStore.pin> pins = PinStore.CopyFromStream(response.GetResponseStream()); //returns a list of PinStore.pin objects, which have name, type, Image, isImage, and Category objects
        System.Collections.ObjectModel.ObservableCollection<SemanticZoomed.zoomedIn> toSource = new System.Collections.ObjectModel.ObservableCollection<SemanticZoomed.zoomedIn>(); //should I be using ObservableCollection or something like List<> here?
        foreach (PinStore.pin pin in pins)
        {
            SemanticZoomed.ZoomedIn toAdd = new SemanticZoomed.ZoomedIn(); //class with Title, Image, isImage, and Category objects
            if (pin.type == "text")
            {
                toAdd.Title = pin.name;
                toAdd.Image = null;
                toAdd.isImage = Visibility.Collapsed;
                toAdd.Category = pin.category;
            }
            toSource.Add(toAdd);
        }
        ItemsGridView.DataContext = toSource;

私は XAML/C# の経験が少なく、バインディングの経験もありません。エラーは発生していませんが、空のスタックパネルに置き換えるItemsGridView.DataContext = toSource;ItemsGridView.ItemsSource = toSource;GridViewに表示され、指定したタイトルとカテゴリの値でそれを埋める方法が見つからないようです。ありがとう!

4

1 に答える 1

1

アイテム スタイルを保存できるように、まず ResourceDictionary の作成を検討する必要があります。次に、ItemStyle をリソース ディクショナリに設定できます。

しかし、あなたがする必要があるにもかかわらず:ItemsGridView.ItemsSource = toSource; GridView xaml で toSource をバインドすることを選択しない場合。

また、SemanticZoomed.zoomedIn オブジェクトが INotifyPropertyChanged インターフェイスを実装し、イベントを適切に呼び出すことを確認してください。また、タイトル、画像、カテゴリなどは、編集時にイベントを呼び出すパブリック プロパティであることを確認してください。また、 pin.Text が実際の値であることを確認する必要があります。{確かめる}。

データ バインディングについて詳しく知りたい場合は、Windows 8 を使用した C# および XAML での方法を確認してください {同じはずです}: http://msdn.microsoft.com/en-us/library/windows/apps/ xaml/hh464965.aspx

于 2012-08-26T00:10:41.703 に答える