Is it possible to make something to set StringFormat of Binding property for all (or part of) TextBoxes in project? Yes, I can write something like
<TextBox x:Name="SetPosition" Style="{StaticResource TextBoxSmallStyle}" Text="{Binding SetPosition, Mode=TwoWay, StringFormat='{}{0:#0.0}'}" />
but setting it for many identical TextBoxes it too boring ))) As you see I am used Style which include Heigth, Width e.t.c. I can't override Binding property in Style because need to use this Style with any Binding Path properties but Binding overrides only wholly. Are where any workarounds exists? P.S. I am already using not standard TextBox but overrided control for my special functionality. Can I override Binding for using compoment's code-behind, maybe?
Since you said you have already extended
TextBoxyou can simply enhance that type and modify the existingBindingon theTextBox.Textproperty.The following example shows how the
ExtendedTextBoxallows to provide a string format expression which is assigned to the currentBinding.Any locally set
Binding.StringFormatvalues are overwritten with theExtendedTextBox.TextStringFormatproperty value.If you also want to apply the string formatting when there is no
Bindingset on theTextproperty, you would have to monitor theTextproperty for changes.App.xaml
Define a global
Stylethat defines the actual string format: