0
是否可以像這樣設置ComboBoxItem的FontWeight?代碼中的C#樣式ComboBoxItem
comboCategory.Items.Add("foo");
(comboCategory.Items[0] as ComboBoxItem).FontWeight = FontWeights.Bold;
Visual Studio喜歡這段代碼,但是在運行時我得到一個NullReferenceException。
我也可以使用此代碼,但我要找的東西更聰明:
ComboBoxItem temp = new ComboBoxItem();
temp.FontWeight = FontWeights.Bold;
temp.Content = "foo";
comboCategory.Items.Add(temp);
好吧,我只有4-5 ComboBoxItems其中fontWeight設置應該大膽。所以我並不需要設置自己的DrawMode。 也許有人可以解釋,爲什麼我的第一個代碼示例拋出異常。 – Johann 2013-03-14 11:04:48