简体   繁体   中英

MultiLine in listbox item c#

I'm trying to put data with linebreakes to one item in listbox

how I make a breaklines in this command?

listBox1.Items.Add("");

or other command

我的意思的例子

thanks

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; }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM