具有int数组的BindingList更新列表框?

| 我有一个如下的BindingList:
private BindingList<int[]> sortedNumbers = new BindingList<int[]>();
每个条目都是一个int [6],现在我想将其绑定到一个列表框,以便每次向其添加一组数字时都会对其进行更新。
listBox1.DataSource = sortedNumbers;
结果是每个条目的以下文本:
Matriz Int32[].
如何格式化输出或更改其输出,以便在生成每个条目集时打印它们的编号?     
已邀请:
您需要处理
Format
事件:
listBox1.Format += (o,e) => 
 { 
    var array = ((int[])e.ListItem).Select(i=>i.ToString()).ToArray();
    e.Value = string.Join(\",\", array);
 };
    
如何在ItemTemplate中使用IValueConverter?
<ListBox x:Name=\"List1\" >
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <TextBlock Text=\"{Binding Converter={StaticResource  NumberConverter}}\" />
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>

public class NumberConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        if (value is int[])
        {
            int[] intValues = (int[])value;
            return String.Join(\",\", intValues);
        }
        else return Binding.DoNothing;
    }

    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        return Convert(value, targetType, parameter, culture);
    }
}
    

要回复问题请先登录注册