5

リスト内のコンボボックスアイテムをたとえば2列に表示するように「強制」することはできますか?

たとえば、次のようになります。

CB選択アイテム

CBアイテム1| CBアイテム4

CBアイテム2| CBアイテム5

CBアイテム3|

4

4 に答える 4

6

XAML は次のとおりです。

<ComboBox Name="ComboBox">
    <ComboBox.ItemsPanel>
        <ItemsPanelTemplate>
            <UniformGrid Columns="2"/>
        </ItemsPanelTemplate>
    </ComboBox.ItemsPanel>
</ComboBox>

簡単なテストでは、0 から 8 までの数字を追加すると、次のようになります。

コンボ ボックスの均一なグリッド

これで、好きなようにスタイルを設定できます... :)

もちろん、誤解がないように、すべての項目 (この場合はすべての番号) は個別のクリック可能な項目です。

[編集]「反対の方法」、つまり「行」の方向でやりたいことに気づきました。そうであれば、WrapPanel誰かが他の回答で提案したように、代わりにを使用する方がよいでしょう。はUniformGrid、最初に列方向にグリッドを塗りつぶします。

でそれを行う方法があるかもしれませUniformGridんが、明らかで簡単なワンクリック変更はありません(以前はここで間違っていました:))

于 2013-02-04T13:23:22.157 に答える
6

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>
于 2013-02-04T13:23:44.540 に答える
2

コンボボックスのに 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>

ここに画像の説明を入力

于 2013-02-04T13:15:23.240 に答える
0

コントロール テンプレートを変更してグリッドを使用し、コンバーターを使用して cbitem の列と行を決定することができます。ただし、選択したアイテムをどのように処理するかはわかりません。

于 2013-02-04T13:12:27.370 に答える