【问题标题】:one item in combobox is bold other are not bold - how to make it?组合框中的一项是粗体,其他不是粗体 - 如何制作?
【发布时间】:2010-06-11 07:54:06
【问题描述】:

美好的一天! 我在 silverliht 应用程序中有一个组合框

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

并将 City 类的项目列表绑定到它。 City 类的项目有一个属性 isCapital 列表中只有一个或没有任何具有 isCapital = true 的项目 我想让 isCapital = true 的项目在组合框中加粗,其他项目不加粗。 我该怎么做?

【问题讨论】:

    标签: silverlight-3.0 combobox


    【解决方案1】:

    我认为最简单的方法是将 FontWeigth 属性添加到您的 City 类,或者更好地创建继承类 CityUI,您将在其中存储所有与视觉相关的内容。然后 DataBind 到 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> 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-02-23
      • 2015-11-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-21
      相关资源
      最近更新 更多