【问题标题】:combobox template problems wpf组合框模板问题 wpf
【发布时间】:2011-11-08 12:15:04
【问题描述】:

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

这是 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>

我错过了什么?

【问题讨论】:

  • Timur,您是否正在使用只读组合来显示查找数据?模板中的任何元素都不会绑定到组合框的选定值。您将需要绑定到 SelectedItem 属性的 TextBox 或 Lable。
  • 您已经提供了样式,但是带有内容的组合框 XAML 本身在哪里?
  • 不知道怎么加))))

标签: c# .net wpf xaml combobox


【解决方案1】:

您的模板几乎没有创建任何内容,这使得默认模板可以正常工作,即没有项目弹出,并且所选项目也没有ContentPresenter。查看默认模板,您将确切地看到您缺少什么(Here 是一个解释从哪里获取它们的问题)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多