Can I set a binding property of TextBox with Styles? [modified]
-
I have many TextBox that their Text property bind to model and this code is is repetetive: e.g.
<TextBox x:Name="Title" Text="{Binding Model.Title , UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=true , ValidatesOnExceptions = true }"> </TextBox>
Can I set 'UpdateSourceTrigger' , 'ValidatesOnDataErrors' and 'ValidatesOnExceptions' with using styles? How? thxmodified on Monday, May 24, 2010 2:15 AM
-
I have many TextBox that their Text property bind to model and this code is is repetetive: e.g.
<TextBox x:Name="Title" Text="{Binding Model.Title , UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=true , ValidatesOnExceptions = true }"> </TextBox>
Can I set 'UpdateSourceTrigger' , 'ValidatesOnDataErrors' and 'ValidatesOnExceptions' with using styles? How? thxmodified on Monday, May 24, 2010 2:15 AM
Hi, yes, you can. And it's just as simple as you can imagine. Where you now write
<TextBox
...
Text="{Binding ...}" />make it into a style with
<Style
...
<Setter
Property="Text"
Value="{Binding ...}" />
</Style>I just used "UpdateSourceTrigger" and it works; so why would the other binding-parameters refuse... Cheers Jürgen
-
Hi, yes, you can. And it's just as simple as you can imagine. Where you now write
<TextBox
...
Text="{Binding ...}" />make it into a style with
<Style
...
<Setter
Property="Text"
Value="{Binding ...}" />
</Style>I just used "UpdateSourceTrigger" and it works; so why would the other binding-parameters refuse... Cheers Jürgen
thanks but it doesn't work! because my binding value is different and just its configuration is the same. this is my code:
<UserControl.Resources>
<Style TargetType="TextBox">
<Setter Property="MinWidth" Value="160" />
</Style>
</UserControl.Resources>...
<TextBox x:Name="Name" Text="{Binding Model.Name , UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=true , ValidatesOnExceptions = true }" /> <TextBox x:Name="Title" Text="{Binding Model.Title , UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=true , ValidatesOnExceptions = true }" />