我知道:
String test = "test";
ListBox.Items.Add(test);
或
String test = "test";
int index = 1;
ListBox.Items.Insert(index, String);
在ListBox中添加了String,但是我想插入ListBoxItem,怎么办? 以前我了解到
var contentToString = (String)ListBoxItem.Content;
简单地将ListBoxItem转换为String,但我不能做相反的事情将String转换为ListBoxItem
最佳答案
试试这个:
ListBoxItem itm = new ListBoxItem();
itm.Content = "some text";
listbox.Items.Add(itm);
listbox 是 ListBox 的名称。
关于c# - 在 C# 的 ListBox 中添加 ListBoxItem?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13267657/