如何在 Combobox 中填充几个矩形样式?
How to populate a few rectangle styles in a Combobox?
我有一个组合框,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# 中的代码中填充它。
这是你想要的吗:
<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>
这是结果:
我有一个组合框,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# 中的代码中填充它。
这是你想要的吗:
<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>
这是结果: