リスト内のコンボボックスアイテムをたとえば2列に表示するように「強制」することはできますか?
たとえば、次のようになります。
リスト内のコンボボックスアイテムをたとえば2列に表示するように「強制」することはできますか?
たとえば、次のようになります。
XAML は次のとおりです。
<ComboBox Name="ComboBox">
<ComboBox.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Columns="2"/>
</ItemsPanelTemplate>
</ComboBox.ItemsPanel>
</ComboBox>
簡単なテストでは、0 から 8 までの数字を追加すると、次のようになります。
これで、好きなようにスタイルを設定できます... :)
もちろん、誤解がないように、すべての項目 (この場合はすべての番号) は個別のクリック可能な項目です。
[編集]「反対の方法」、つまり「行」の方向でやりたいことに気づきました。そうであれば、WrapPanel
誰かが他の回答で提案したように、代わりにを使用する方がよいでしょう。はUniformGrid
、最初に列方向にグリッドを塗りつぶします。
でそれを行う方法があるかもしれませUniformGrid
んが、明らかで簡単なワンクリック変更はありません(以前はここで間違っていました:))
ItemsPanel を WrapPanel に変更できますが、高さに注意してください (アイテムの数に応じて計算するコンバーターを作成できます)。
<ComboBox>
<ComboBox.Resources>
<Style TargetType="ComboBox">
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<WrapPanel IsItemsHost="True" Orientation="Vertical" Width="100" Height="50" />
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="ComboBoxItem">
<Setter Property="Width" Value="50" />
</Style>
</ComboBox.Resources>
<ComboBoxItem Content="Value 1" />
<ComboBoxItem Content="Value 2" />
<ComboBoxItem Content="Value 3" />
<ComboBoxItem Content="Value 4" />
<ComboBoxItem Content="Value 5" />
</ComboBox>
コンボボックスのに aWrapPanel
を入れる必要があります。ItemsPanel
<ComboBox>
<ComboBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Vertical" Height="100" />
</ItemsPanelTemplate>
</ComboBox.ItemsPanel>
<ComboBoxItem Content="Value 1" />
<ComboBoxItem Content="Value 2" />
<ComboBoxItem Content="Value 3" />
<ComboBoxItem Content="Value 4" />
<ComboBoxItem Content="Value 5" />
<ComboBoxItem Content="Value 6" />
<ComboBoxItem Content="Value 7" />
<ComboBoxItem Content="Value 8" />
<ComboBoxItem Content="Value 9" />
<ComboBoxItem Content="Value 10" />
<ComboBoxItem Content="Value 11" />
<ComboBoxItem Content="Value 12" />
<ComboBoxItem Content="Value 13" />
<ComboBoxItem Content="Value 14" />
<ComboBoxItem Content="Value 15" />
</ComboBox>
コントロール テンプレートを変更してグリッドを使用し、コンバーターを使用して cbitem の列と行を決定することができます。ただし、選択したアイテムをどのように処理するかはわかりません。