tags:

views:

29

answers:

1

I have a control in my XAML bound to a property with a style.

<TextBox x:Name="txtCapAmount" Text="{Binding Path=CapAmount}" Style="{DynamicResource AmountTextBoxStyle}"  />

In the style I'd like to use the Binding from the control but am not sure how to set it

<Style x:Key="AmountTextBoxStyle" TargetType="{x:Type TextBox}">
    <EventSetter Event="TextBox.PreviewTextInput" Handler="PreviewTextInput_IsTheNewValueAnAcceptableAmount" />
    <EventSetter Event="CommandManager.PreviewExecuted" Handler="CommandPaste_IsTheNewValueAnAcceptableAmount" />
    <Setter Property="MinWidth" Value="100" />
    <Setter Property="Text" Value="{Binding Path=?????, TargetNullValue={x:Static System:String.Empty}, StringFormat={}{0:C0}}" />
</Style>

I want to reuse this style for multiple textboxes throughout the application but need to bind each individual textbox to a different property. In the style, is it possible alter the 'Text' property while retaining the Path set on the control?

+1  A: 

You are using styles incorrectly here. A style should be used similar to CSS on the web, to alter the visual appearance of multiple instances of similar controls.

Why do you need the text in the style at all? You are already binding the text at the control instance level. Putting it in the style doesn't gain you anything, and as you have found just won't work

Foovanadil
The key is to not copy and paste the TargetNullValue and StringFormat binding values across the entire application. I would like to set those in a resource dictionary (one place only). I certainly could set the Text property on the control but I'm really looking for another answer.
Scott Simock