我有一个组合框,并且在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>
这是结果: