Reputation: 4579
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? - i.e. 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?
Upvotes: 2
Views: 2360
Reputation: 169160
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
, i.e. 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}}
Upvotes: 4