Created
January 24, 2012 21:22
-
-
Save CodingGorilla/1672789 to your computer and use it in GitHub Desktop.
Uses the Validation.ErrorTemplate to create a popup error indicator on a WPF TextBox control
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Style TargetType="{x:Type TextBox}"> | |
<Setter Property="Validation.ErrorTemplate"> | |
<Setter.Value> | |
<ControlTemplate> | |
<Grid> | |
<Border BorderBrush="#FFCB2E2E" BorderThickness="1" Background="#11FF0000" IsHitTestVisible="False" x:Name="errorBorder"/> | |
<AdornedElementPlaceholder x:Name="placeholder" /> | |
<Popup AllowsTransparency="True" HorizontalAlignment="Right" HorizontalOffset="0" VerticalOffset="0" PopupAnimation="Fade" Placement="Right" | |
PlacementTarget="{Binding ElementName=errorBorder}" IsOpen="{Binding ElementName=placeholder, Path=AdornedElement.IsFocused, Mode=OneWay}"> | |
<StackPanel Orientation="Horizontal"> | |
<Polygon VerticalAlignment="Center" Points="0,4 4,0 4,8" Fill="#FFCB2E2E" Stretch="Fill" Stroke="#FFCB2E2E" | |
StrokeThickness="2" /> | |
<Border Background="#FFCB2E2E" CornerRadius="4" Padding="4"> | |
<TextBlock HorizontalAlignment="Center" Foreground="White" FontWeight="Bold" Margin="2,0,0,0" | |
Text="{Binding ElementName=placeholder, Path=AdornedElement.ToolTip, Mode=OneWay}" /> | |
</Border> | |
</StackPanel> | |
</Popup> | |
</Grid> | |
</ControlTemplate> | |
</Setter.Value> | |
</Setter> | |
<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> |
to solve this, you have to create a custom control, that inherits from window, so then you can move or resize
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It looks nice. Sadly, the problem with popups is that they retain their original position when the containing window is moved or resized.