我是从arrayList绑定listboxitems。这个arraylist包含所有textbox和combobox文本。现在我的问题是如何通过代码而不是xaml我只能使一个listitem字体变为粗体。因为我没有从xaml添加列表框项目。< / p>
任何建议,想法实现这个..
提前感谢。
编辑:
XAML:
<ListBox Name="lstbx" Width="200" HorizontalAlignment="Left" Margin="0,0,0,0" BorderBrush="Transparent" > </ListBox>
代码:
private ArrayList LoadListData()
{
ArrayList arrList = new ArrayList();
//txtFullName.FontWeight = FontWeights.Bold; //this didnt work
arrList.Add(txtFullName.Text);
arrList.Add(" ");
}
lstbx.ItemsSource=LoadListData();
答案 0 :(得分:1)
我不知道这是否是您想要的,但基本上我正在用TextBlocks填充列表框并按我的意愿设置文本内容。仅供演示:
private void MakeBold()
{
for (int i = 0; i < 5; i++)
{
TextBlock s = new TextBlock();
s.Text = "Testing" + i;
if (i == 3)
s.FontWeight = FontWeights.Heavy;
lstbx.Items.Add(s);
}
}
我得到了这个结果:
我希望这会有所帮助。
答案 1 :(得分:0)
我假设txtFullName
以编程方式声明。即使您以编程方式设置FontWeight
,您仍然只将文本添加到列表中,并且重量信息永远不会传递。
传递整个TextBox
,它应该有效:
arrList.Add(txtFullName);