2
我有一個TextBox以下樣式:文本框驗證工具提示中不顯示
<Style x:Key="RenamingTextBox" TargetType="{x:Type TextBox}">
<Style.Setters>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type TextBox}">
<Grid>
<TextBlock x:Name="block" Visibility="Visible" Text="{TemplateBinding Text}" Margin="0"/>
<TextBox x:Name="box" Visibility="Collapsed"
Text="{Binding Text, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
Margin="1.25"/>
</Grid>
<ControlTemplate.Triggers>
<DataTrigger Binding="{Binding IsRenaming}" Value="true">
<DataTrigger.Setters>
<Setter TargetName="block" Property="TextBox.Visibility" Value="Collapsed" />
<Setter TargetName="box" Property="TextBox.Visibility" Value="Visible" />
<Setter TargetName="box" Property="FocusManager.FocusedElement" Value="{Binding ElementName=box}" />
<Setter TargetName="box" Property="behaviors:TextBoxBehavior.SelectAll" Value="True"/>
</DataTrigger.Setters>
</DataTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style.Setters>
</Style>
也:
<Style TargetType="{x:Type TextBox}">
<Setter Property="Margin" Value="5" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="BorderBrush" Value="LightGray" />
<Style.Triggers>
<Trigger Property="Validation.HasError" Value="True">
<Setter Property="ToolTip"
Value="{Binding RelativeSource={RelativeSource Self},
Path=(Validation.Errors)[0].ErrorContent}"/>
</Trigger>
</Style.Triggers>
</Style>
重命名文本框的偉大工程,它的變化來回TextBox控件以及到文本塊沒問題。當我的名字出現錯誤時,它甚至會得到漂亮的紅色邊框。問題是,當我將鼠標懸停在文本框上並出現錯誤時,工具提示沒有顯示出來。項目中的所有其他文本框都正常工作。有任何想法嗎?
沒錯,就是這樣,OOPS!我總是忘記了BasedOn! – KrisTrip 2012-04-24 15:52:15