【发布时间】:2011-04-04 11:50:54
【问题描述】:
我的 XAML 中有一个控件绑定到具有样式的属性。
<TextBox x:Name="txtCapAmount" Text="{Binding Path=CapAmount}" Style="{DynamicResource AmountTextBoxStyle}" />
在样式中我想使用控件中的绑定,但不知道如何设置它
<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>
我想在整个应用程序中为多个文本框重复使用这种样式,但需要将每个单独的文本框绑定到不同的属性。在样式中,是否可以在保留控件上设置的路径的同时更改“文本”属性?
【问题讨论】:
-
你尝试过 Binding Path=Text 吗?