Given a WPF text box, as an example:
<TextBox Text="{Binding Path=blahProperty, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, StringFormat=\{0:yyyy.MM.dd HH:mm:ss\}}"/>
Could the StringFormat I've got there instead be bound to an underlying property string? - ie could the "yyyy.MM.dd HH:mm:ss" be provided by a property on the View (or ViewModel) instead of being hard-coded in the xaml?
No, a {Binding}
cannot be set on the StringFormat
property of the Binding
because StringFormat
is not a dependency property.
You can only bind to a DependencyProperty
of a DependencyObject
, ie the target property of a binding must be a dependency property.
You may set it to the the value of static property though:
StringFormat={x:Static local:MainWindow.StaticProperty}}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.