组合框模板问题wpf

时间:2011-11-08 12:15:04

标签: c# .net wpf xaml combobox

我已经为组合框创建了模板,但它有奇怪的视图,数据没有显示:

enter image description here

这是XAML代码:

 <Style TargetType="{x:Type ComboBox}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type ComboBox}">
                <Border Background="{TemplateBinding Background}" x:Name="Bd" BorderBrush="Gray" BorderThickness="2" CornerRadius="2">
                </Border>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsEnabled" Value="False">
                        <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" TargetName="Bd"/>
                        <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                    </Trigger>
                    <Trigger Property="IsFocused" Value="true">
                        <Setter Property="BorderBrush" Value="Blue" TargetName="Bd"/>
                        <Setter Property="BorderThickness" Value="2"/>
                    </Trigger>
                    <Trigger Property="IsFocused" Value="false">
                        <Setter Property="BorderBrush" Value="Gray" TargetName="Bd"/>
                        <Setter Property="BorderThickness" Value="2"/>
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>

    </Setter>
</Style>

我错过了什么?

1 个答案:

答案 0 :(得分:2)

您的模板创建几乎没有任何内容使默认设置工作,即没有项目弹出,并且所选项目也没有ContentPresenter。看一下默认模板,你会看到你遗漏的确切内容(Here是一个解释从何处获取它们的问题。)