gpt4 book ai didi

c# - 在 C# 的 ListBox 中添加 ListBoxItem?

转载 作者:IT王子 更新时间:2023-10-29 04:33:55 25 4
gpt4 key购买 nike

我知道:

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com