![](/img/trans.png)
[英]How to set Unicode character as Text of TextBlock in the code-behind?
[英]How to set the text of a ListBox in code-behind design
我有一个System.Windows.Control.ListBox ,我想选择一个特定的索引。 例如,我的列表框是红色,白色和蓝色,并且在读取对象/文件之后,我想在窗口出现时选择红色。 最好的方法是什么?
public partial class MyWindow : System.Windows.Window
{
public MyWindow()
{
InitializeComponent();
System.Windows.Control.ListBox MyListBox= (ListBox)this.FindName("myListBox");
}
}
您可以只使用ListBox.SelectedIndex属性...
public MyWindow()
{
InitializeComponent();
yourListBox.SelectedIndex = indexOfRed;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.