3枚の画像を連続して表示したいListBox
。WrapPanel
仮想化が失われるため使用できません。だから私は使用しますVirtualizingStackPanel
。
私のListBoxItem
テンプレートには、水平方向に 3 つの画像がありStackPanel
ます。ユーザーが単一の画像をクリックできるようにしたいのですが、ListBox
のデフォルトの動作では全体をクリックすることしかできませんListBoxItem
。
どうやってするか ?
3枚の画像を連続して表示したいListBox
。WrapPanel
仮想化が失われるため使用できません。だから私は使用しますVirtualizingStackPanel
。
私のListBoxItem
テンプレートには、水平方向に 3 つの画像がありStackPanel
ます。ユーザーが単一の画像をクリックできるようにしたいのですが、ListBox
のデフォルトの動作では全体をクリックすることしかできませんListBoxItem
。
どうやってするか ?
行全体を選択したくない場合は、のItemsControl
代わりに切り替える必要がありListBox
ます。
すべての行で画像を選択できるようにするにはItemTemplate
、これItemsControl
を画像のコレクションにバインドされたリストボックスに設定します。
動作するはずのサンプルコードを次に示します。
<ItemsControl ItemsSource="{Binding Collection}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<!--THe ItemTemplate is a ListBox of Images-->
<ListBox>
<ListBox.ItemTemplate ItemsSource="{Binding Images}">
<DataTemplate>
<Image Source="{Binding Img}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<!--This is required to have the scroll-->
<ItemsControl.Template>
<ControlTemplate TargetType="ItemsControl">
<Border>
<ScrollViewer>
<ItemsPresenter/>
</ScrollViewer>
</Border>
</ControlTemplate>
</ItemsControl.Template>
</ItemsControl>