【发布时间】:2016-02-03 00:48:39
【问题描述】:
当我收到 ValidationError 时,我无法弄清楚为什么我的 TextBox 周围会出现额外的红色边框!我只想要样式中设置的边框周围的边框颜色,但是它周围有一个额外的矩形边框,我不知道如何摆脱它!
这是我的文本框样式:
<Style x:Key="DefaultTextbox" TargetType="TextBox" xmlns:Helpers="clr-namespace:PhotoManagement.Helpers">
<Setter Property="Helpers:WaterMarkTextHelper.IsMonitoring" Value="True"/>
<Setter Property="Helpers:WaterMarkTextHelper.WatermarkText" Value="{Binding RelativeSource={RelativeSource Self}, Path=Tag}" />
<Setter Property="Background" Value="#FF22252C" />
<Setter Property="Foreground" Value="White" />
<Setter Property="BorderBrush" Value="#FF22252C" />
<Setter Property="Width" Value="200" />
<Setter Property="Cursor" Value="IBeam" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="TextBox">
<DockPanel>
<Popup Name="ErrorPopup" IsOpen="False" Placement="Top">
<TextBlock Background="White" Foreground="Black" Text="Test" Padding="5" />
</Popup>
<Border CornerRadius="5"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="1"
Background="{TemplateBinding Background}"
Margin="3"
MinWidth="{TemplateBinding MinWidth}">
<Grid>
<StackPanel Margin="8">
<ScrollViewer x:Name="PART_ContentHost"/>
</StackPanel>
<TextBlock Name="PART_TempText"
Text="{TemplateBinding Tag}"
Foreground="#FF454954"
Padding="8"
Margin="5 0" />
</Grid>
</Border>
</DockPanel>
<ControlTemplate.Triggers>
<Trigger Property="Validation.HasError" Value="True">
<Setter Property="BorderBrush" Value="Red" />
<Setter TargetName="ErrorPopup" Property="IsOpen" Value="True" />
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="Helpers:WaterMarkTextHelper.HasText" Value="False"/>
<Condition Property="IsFocused" Value="True"/>
</MultiTrigger.Conditions>
<MultiTrigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource enterGotFocus}"/>
</MultiTrigger.EnterActions>
<MultiTrigger.ExitActions>
<BeginStoryboard Storyboard="{StaticResource exitGotFocus}"/>
</MultiTrigger.ExitActions>
</MultiTrigger>
<Trigger Property="Helpers:WaterMarkTextHelper.HasText" Value="True">
<Trigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource enterHasText}"/>
</Trigger.EnterActions>
<Trigger.ExitActions>
<BeginStoryboard Storyboard="{StaticResource exitHasText}"/>
</Trigger.ExitActions>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
这是我在本文底部发布的 ContentControl 上的 ControlTemplate,其中包含 TextBox。
<ControlTemplate x:Key="InputFields" TargetType="ContentControl">
<Grid>
<i:Interaction.Triggers>
<local:RoutedEventTrigger RoutedEvent="{x:Static Validation.ErrorEvent}">
<e2c:EventToCommand
Command="{Binding EditVM.TheEntity.ConversionErrorCommand, Mode=OneWay}"
EventArgsConverter="{StaticResource BindingErrorEventArgsConverter}"
PassEventArgsToCommand="True" />
</local:RoutedEventTrigger>
<local:RoutedEventTrigger RoutedEvent="{x:Static Binding.SourceUpdatedEvent}">
<e2c:EventToCommand
Command="{Binding EditVM.TheEntity.SourceUpdatedCommand, Mode=OneWay}"
EventArgsConverter="{StaticResource BindingSourcePropertyConverter}"
PassEventArgsToCommand="True" />
</local:RoutedEventTrigger>
</i:Interaction.Triggers>
<ContentPresenter />
</Grid>
</ControlTemplate>
<Style x:Key="ErrorToolTip" TargetType="Control">
<Style.Triggers>
<Trigger Property="Validation.HasError" Value="true">
<Setter Property="ToolTip" Value="{Binding RelativeSource={x:Static RelativeSource.Self},
Path=(Validation.Errors), Converter={StaticResource ErrorCollectionConverter}}"/>
</Trigger>
</Style.Triggers>
</Style>
内容控制
<ContentControl Template="{StaticResource InputFields}">
<StackPanel>
<WrapPanel>
<TextBox Tag="First Name..."
Text="{Binding EditVM.TheEntity.FName,
UpdateSourceTrigger=PropertyChanged,
NotifyOnSourceUpdated=True,
NotifyOnValidationError=True,
Mode=TwoWay}">
<TextBox.Resources>
<Style TargetType="ToolTip">
<Setter Property="StaysOpen" Value="True" />
<Setter Property="Placement" Value="Center" />
<Setter Property="IsOpen" Value="True" />
</Style>
</TextBox.Resources>
</TextBox>
<TextBox Tag="Last Name..."
Text="{Binding EditVM.TheEntity.LName,
UpdateSourceTrigger=PropertyChanged,
NotifyOnSourceUpdated=True,
NotifyOnValidationError=True,
Mode=TwoWay}"/>
<TextBox Tag="Email Address..."
Text="{Binding EditVM.TheEntity.Email,
UpdateSourceTrigger=PropertyChanged,
NotifyOnSourceUpdated=True,
NotifyOnValidationError=True,
Mode=TwoWay}"/>
</WrapPanel>
</StackPanel>
</ContentControl>
【问题讨论】: