Skip to content

Instantly share code, notes, and snippets.

@bukowa
Created October 13, 2024 23:02
Show Gist options
  • Select an option

  • Save bukowa/c086785fbc429dbf51447198c3e356f2 to your computer and use it in GitHub Desktop.

Select an option

Save bukowa/c086785fbc429dbf51447198c3e356f2 to your computer and use it in GitHub Desktop.
code
<Grid.Resources>
<Style TargetType="TextBox">
<Setter Property="Padding" Value="2 1"></Setter>
<Setter Property="BorderBrush" Value="Black"></Setter>
<Setter Property="BorderThickness" Value="1"></Setter>
<Setter Property="Validation.ErrorTemplate">
<Setter.Value>
<ControlTemplate>
<AdornedElementPlaceholder></AdornedElementPlaceholder>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="TextBox">
<StackPanel>
<Border
Padding="{TemplateBinding Padding}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="5">
<ScrollViewer x:Name="PART_ContentHost" />
</Border>
<ItemsControl ItemsSource="{Binding RelativeSource={RelativeSource AncestorType={x:Type TextBox}}, Path=(Validation.Errors)}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock Foreground="Red" Text="{Binding ErrorContent}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Grid.Resources>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment