【发布时间】:2015-09-02 17:19:46
【问题描述】:
我有一个ComboBox,它是数据绑定的,我无法插入哨兵项目。如果 ComboBox 中没有选定的值,我想显示一个默认字符串。
我已经尝试过为此使用样式:
<ComboBox.Style>
<Style TargetType="ComboBox">
<Style.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=SelectedIndex}" Value="-1">
<Setter Property="Text" Value="(unconstrained)" />
</DataTrigger>
</Style.Triggers>
</Style>
</ComboBox.Style>
但这完全破坏了数据绑定(没有可选的值)。
【问题讨论】:
-
在组合框中使用此代码
PlaceholderText="MyPlaceholder" -
看看这个stackoverflow.com/questions/1426050/…也许是你需要的。
-
@soumyasambitKunda:
System.Windows.Controls.ComboBox没有PlaceholderText属性。也许那是 WinForms? -
@Andrey: 是的,这个 hack 有效 :)