如何在组合框中填充一些矩形样式?

问题描述 投票:1回答:1

我有一个组合框,并且在XAML中有一个像这样的小模板:

<ComboBox Name="cboStyles" Grid.Column="1" Grid.Row="5">
    <ComboBox.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal" Height="15" Width="Auto">
                <!-- Don't know what to do here. -->
            </StackPanel>
        </DataTemplate>
    </ComboBox.ItemTemplate>
</ComboBox>

[我想在其中填充一些具有不同边框样式(如虚线和虚线)的矩形。更好的是从C#后面的代码中填充它。

c# wpf xaml combobox rectangles
1个回答
0
投票

这是您想要的吗?

<ComboBox Name="cboStyles" Grid.Column="1" Grid.Row="5" Height="100">
        <Rectangle Stroke="Black" Margin="5" Width="50" Height="50" StrokeDashArray="5" StrokeThickness="2" StrokeDashOffset="2"></Rectangle>
        <Rectangle Stroke="Blue" Margin="5" Width="50" Height="50" StrokeDashArray="5" StrokeThickness="2" StrokeDashOffset="2"></Rectangle>
        <Rectangle Stroke="Green" Margin="5" Width="50" Height="50" StrokeDashArray="5" StrokeThickness="2" StrokeDashOffset="2"></Rectangle>
        <Rectangle Stroke="Red" Margin="5" Width="50"  Height="50" StrokeDashArray="5" StrokeThickness="2" StrokeDashOffset="2"></Rectangle>
    </ComboBox>

这是结果:“在此处输入图像描述”

© www.soinside.com 2019 - 2024. All rights reserved.