开发者

one item in combobox is bold other are not bold - how to make it?

Good day! I have a combobox in a silverliht application

<ComboBox  x:Name="cbCities" Width="500" Height="24"/>

and bind to it a list of items of City class. The items of City class have a property isCapital There is an only one or no any items with isCapital = true in the list I want to make the item with isCapital = true to be bold in the combob开发者_JS百科ox, and other items not ot be bold. How can I do it?


The simplest way I think is either add FontWeigth property to your City class or even better to create Inherited class CityUI where you will store all your visual related things. And then DataBind to this property in DataTemplate.

public partial class City
{
        public FontWeight FontWeight
        {
            get
            {
                if (isCapital) return FontWeights.Bold;
                return FontWeights.Normal;
            }
        }
}

<ComboBox.ItemTemplate>
    <DataTemplate>
        <TextBlock FontWeight="{Binding Path=FontWeight}" Text="{Binding Path=Name}"/>
    </DataTemplate>
</ComboBox.ItemTemplate> 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜