【问题标题】:MultiLine in listbox item c#列表框项目中的多行 c#
【发布时间】:2017-08-15 23:56:00
【问题描述】:

我正在尝试将带有换行符的数据放入列表框中的一项

如何在这个命令中创建断线?

listBox1.Items.Add("");

或其他命令

谢谢

【问题讨论】:

标签: c# listbox multiline


【解决方案1】:
public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();

        var product = new Product
        {
            ProductName = "Some name",
            Id = "123X",
            Size = "Big",
            OutOfStock = "true"
        };

        var itm = new ListBoxItem {Content = $"Product Name: {product.ProductName} {Environment.NewLine}" +
                                             $"ID: {product.Id} {Environment.NewLine}" +
                                             $"Size: {product.Size} {Environment.NewLine}" +
                                             $"Out of stock {product.OutOfStock}"
        };

        listBox.Items.Add(itm);
    }
}

public class Product
{
    public string ProductName { get; set; }
    public string Id { get; set; }
    public string Size { get; set; }
    public string OutOfStock { get; set; }
}

【讨论】:

  • 它不起作用,因为 ListboxItem 适用于 wpf 而不是 windows 形式
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-09-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-17
相关资源
最近更新 更多