我在用户控件上有一个带有绑定(bind)属性的标签。需要根据绑定(bind)到标签内容属性的基础数据的数据类型来设置此绑定(bind)的字符串格式属性。因此,如果该属性绑定(bind)到我的 View 模型中的日期属性,我想在数据触发器中指定字符串格式。这是我尝试过的,但 StringFormat 未被识别。我错过了什么还是我做错了?任何建议将不胜感激。
<Label
x:Name="myLabel"
Content="{Binding Path=myProperty}">
<Label.Style>
<Style>
<Style.Triggers>
<DataTrigger
Binding="{Binding ElementName=myLabel, Path=Content.Binding}"
Value="{x:Type sys:DateTime}">
<Setter
Property="StringFormat"
Value="dd/MM/yyyy" />
</DataTrigger>
</Style.Triggers>
</Style>
</Label.Style>
最佳答案
为什么不简单地使用转换器?
<Label Content="{Binding Path=myProperty, Converter={StaticResource MyContentConverter}}">
关于wpf - 绑定(bind)属性上的 DataTrigger,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17230847/