0
votes

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
have you try the Binding Path=Text ?dnr3

1 Answers

1
votes

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