【发布时间】:2015-08-05 11:52:14
【问题描述】:
我的 WPF 应用程序中有一个 LabeledTextBox,它非常简单:
<Grid x:Name="root">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0"
Text="{Binding Label}"
FontWeight="Bold"
VerticalAlignment="Bottom"
Margin="5,2,5,0"/>
<TextBox Grid.Row="1"
Text="{Binding Text}"
VerticalAlignment="Top"
Margin="5,0,5,2"/>
</Grid>
我将我所有的模型都绑定到那个人以显示。我已经成功实现了IDataErrorInfo,并且可以设置LabeledTextBox 的样式,例如:
<Style TargetType="controls:LabeledTextBox">
<Style.Triggers>
<Trigger Property="Validation.HasError" Value="true">
<Setter Property="BorderBrush" Value="Red"/>
<Setter Property="BorderThickness" Value="5"/>
</Trigger>
</Style.Triggers>
</Style>
这一切都有效,整个控件的边框是红色的(很明显)。我想要的是在LabeledTextBox 中操作TextBox,我的最终目标是将背景更改为柔和的红色。
当触发器设置在整个 LabeledTextbox 上时,如何从触发器内访问我的 TextBox?
我想这是一个看似简单的任务,我只是无法正确使用语法。我在 .NET4.0 环境中工作,如果相关的话。
谢谢!
【问题讨论】:
标签: c# wpf validation xaml triggers