Reputation: 145
I have the need to give the user the ability to set their own Decimal Formating option in XAML.
I know how to set StringFormat into Binding, but I only know how to do it manually. How can I Bind the String Format value inside a binding.
Upvotes: 1
Views: 1525
Reputation: 169200
How can I Bind the String Format value inside a binding.
You cannot because StringFormat
is not a dependency property.
But you could use a multi binding that binds to two properties, the actual source property and the format source property, and an IMultiValueConverter
class:
WPF Binding and Dynamically Assigning StringFormat Property
WPF: MultiBinding and IMultiValueConverter: https://blog.csainty.com/2009/12/wpf-multibinding-and.html
Upvotes: 0
Reputation: 2877
You can use ContentStringFormat property.
Use it like this:
<TextBox Text="{Binding MyFormat, UpdateSourceTrigger=PropertyChanged}" />
<Label Content="{Binding ValueToFormat}"
ContentStringFormat="{Binding MyFormat}" />
Upvotes: 0