【发布时间】: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 本身在哪里?
-
不知道怎么加))))