[英]How can I change (i.e. toggle) the bound, StringFormat property of a WPF control?
[英]WPF - Can StringFormat be bound to a property?
给定一个WPF文本框,作为示例:
<TextBox Text="{Binding Path=blahProperty, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, StringFormat=\{0:yyyy.MM.dd HH:mm:ss\}}"/>
StringFormat我可以在那里绑定到底层属性字符串吗? - 即“yyyy.MM.dd HH:mm:ss”是否可以由View(或ViewModel)上的属性提供,而不是在xaml中进行硬编码?
不,无法在Binding
的StringFormat
属性上设置{Binding}
,因为StringFormat
不是依赖项属性。
您只能绑定到DependencyProperty
的DependencyObject
,即绑定的target属性必须是依赖属性。
您可以将其设置为静态属性的值,但:
StringFormat={x:Static local:MainWindow.StaticProperty}}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.