在列表列表中显示组合框项目中的列表

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

我目前有一个List<List<Path>>,我想在组合框项目中显示内部列表。粗略地喜欢这个伪:

<ComboBox>
    <ComboBoxItem Content="3 paths"/>
    <ComboBoxItem Content="3 paths"/>
    <ComboBoxItem Content="3 paths"/>
    <ComboBoxItem Content="3 paths"/>
</Combobox>

编辑:添加图像

这就是它现在的样子

Current combobox

这大致是我想要的

enter image description here

在图像中,每行是包含另一个列表的列表,其中包含三角形。

因此,如果最外面的列表中有4个列表项,每个列表中有3个路径,我希望它们像上面那样显示。我现在的设置是这样的

XAML:

<ComboBox ItemsSource="{Binding Path=AvailableCombinationsOfShape}">
    <ComboBox.ItemTemplate>
        <DataTemplate>
            <Path Data="{Binding Path=Data}" StrokeThickness="1" Stroke="Black"/>
        </DataTemplate>
    </ComboBox.ItemTemplate>
</ComboBox>

代码背后:

AvailableCombinationsOfShape = new List<List<Path>>();

foreach (var combination in combinations)
{
    var r = CombineShapes(GetImageShapes(), combination);
    AvailableCombinationsOfShape.Add(r);
    i++;
}      
private List<Path> CombineShapes(List<SymbolShapeModel> shapes, int[] numbersNotToFill)
{
    var pathList = new List<Path>();
    foreach (var shape in shapes)
    {
        var p = new Path();
        p.Data = shape.Shape;
        pathList.Add(p);
    }
    return pathList;
}

有了这个,我得到每个列表中的第一个形状,以显示在组合框中,但我希望显示所有3个形状。

我想要这样的原因是因为我想为每个组合框项目中的一些形状着色。 (想象3个正方形。我希望第一个项目显示正方形1和2颜色,项目2应显示正方形2和3颜色,最后一个项目应显示正方形1和3颜色。)

希望可以有人帮帮我!谢谢!

c# wpf combobox binding
1个回答
1
投票

谢谢@RobinBennett。我需要的只是一个Itemscontrol

<ComboBox ItemsSource="{Binding Path=AvailableCombinationsOfShape, Mode=OneWay}">
    <ComboBox.ItemTemplate>
        <DataTemplate>
            <ItemsControl ItemsSource="{Binding}">
                <ItemsControl.ItemTemplate>
                    <DataTemplate>
                        <Path Data="{Binding Path=Data}" StrokeThickness="1" Stroke="Black"/>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>
        </DataTemplate>
    </ComboBox.ItemTemplate>
</ComboBox>

三角形的位置有点奇怪,但这是一个我能够处理自己的问题。

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