committed by
GitHub
2 changed files with 103 additions and 41 deletions
@ -1,44 +1,102 @@ |
|||||
<Style xmlns="https://github.com/avaloniaui" |
<Styles xmlns="https://github.com/avaloniaui" |
||||
Selector="DataValidationErrors" |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
||||
xmlns:sys="clr-namespace:System;assembly=netstandard"> |
xmlns:sys="using:System"> |
||||
<Design.PreviewWith> |
<Design.PreviewWith> |
||||
<Border Padding="20"> |
<Border Padding="20"> |
||||
<TextBox Text="Sample"> |
<StackPanel Spacing="20"> |
||||
<DataValidationErrors.Error> |
<TextBox Text="Sample"> |
||||
<sys:Exception/> |
<DataValidationErrors.Error> |
||||
</DataValidationErrors.Error> |
<sys:Exception /> |
||||
</TextBox> |
</DataValidationErrors.Error> |
||||
|
</TextBox> |
||||
|
<TextBox Text="Sample"> |
||||
|
<TextBox.Styles> |
||||
|
<Style Selector="DataValidationErrors"> |
||||
|
<Setter Property="Template" Value="{DynamicResource TooltipDataValidationContentTemplate}" /> |
||||
|
<Setter Property="ErrorTemplate" Value="{DynamicResource TooltipDataValidationErrorTemplate}" /> |
||||
|
</Style> |
||||
|
</TextBox.Styles> |
||||
|
<DataValidationErrors.Error> |
||||
|
<sys:Exception /> |
||||
|
</DataValidationErrors.Error> |
||||
|
</TextBox> |
||||
|
</StackPanel> |
||||
</Border> |
</Border> |
||||
</Design.PreviewWith> |
</Design.PreviewWith> |
||||
|
|
||||
<Setter Property="Template"> |
<Style Selector="DataValidationErrors"> |
||||
<ControlTemplate> |
<Style.Resources> |
||||
<DockPanel LastChildFill="True"> |
<DataTemplate x:Key="InlineDataValidationErrorTemplate"> |
||||
<ContentControl Margin="0 4 0 0" |
<ItemsControl Items="{Binding}"> |
||||
DockPanel.Dock="Bottom" |
<ItemsControl.ItemTemplate> |
||||
ContentTemplate="{TemplateBinding ErrorTemplate}" |
<DataTemplate> |
||||
DataContext="{TemplateBinding Owner}" |
<TextBlock Foreground="{DynamicResource SystemControlErrorTextForegroundBrush}" |
||||
Content="{Binding (DataValidationErrors.Errors)}" |
Text="{Binding}" |
||||
IsVisible="{Binding (DataValidationErrors.HasErrors)}" /> |
TextWrapping="Wrap" /> |
||||
<ContentPresenter |
</DataTemplate> |
||||
Name="PART_ContentPresenter" |
</ItemsControl.ItemTemplate> |
||||
Background="{TemplateBinding Background}" |
</ItemsControl> |
||||
BorderThickness="{TemplateBinding BorderThickness}" |
</DataTemplate> |
||||
ContentTemplate="{TemplateBinding ContentTemplate}" |
<ControlTemplate x:Key="InlineDataValidationContentTemplate" TargetType="DataValidationErrors"> |
||||
Content="{TemplateBinding Content}" |
<DockPanel LastChildFill="True"> |
||||
Padding="{TemplateBinding Padding}" /> |
<ContentControl x:Name="InlineDataValidationContentControl" |
||||
</DockPanel> |
Margin="0,4,0,0" |
||||
</ControlTemplate> |
Content="{Binding (DataValidationErrors.Errors)}" |
||||
</Setter> |
ContentTemplate="{TemplateBinding ErrorTemplate}" |
||||
<Setter Property="ErrorTemplate"> |
DataContext="{TemplateBinding Owner}" |
||||
<DataTemplate> |
DockPanel.Dock="Bottom" |
||||
<ItemsControl Items="{Binding}"> |
IsVisible="{Binding (DataValidationErrors.HasErrors)}" /> |
||||
<ItemsControl.ItemTemplate> |
<ContentPresenter Name="PART_ContentPresenter" |
||||
<DataTemplate> |
Padding="{TemplateBinding Padding}" |
||||
<TextBlock Text="{Binding }" Foreground="{DynamicResource SystemControlErrorTextForegroundBrush}" TextWrapping="Wrap" /> |
Background="{TemplateBinding Background}" |
||||
</DataTemplate> |
BorderThickness="{TemplateBinding BorderThickness}" |
||||
</ItemsControl.ItemTemplate> |
Content="{TemplateBinding Content}" |
||||
</ItemsControl> |
ContentTemplate="{TemplateBinding ContentTemplate}" /> |
||||
</DataTemplate> |
</DockPanel> |
||||
</Setter> |
</ControlTemplate> |
||||
</Style> |
|
||||
|
<DataTemplate x:Key="TooltipDataValidationErrorTemplate"> |
||||
|
<Panel Name="PART_InlineErrorTemplatePanel" Background="Transparent"> |
||||
|
<Panel.Styles> |
||||
|
<Style Selector="Panel#PART_InlineErrorTemplatePanel"> |
||||
|
<Setter Property="Margin" Value="8,0" /> |
||||
|
</Style> |
||||
|
<Style Selector="Panel#PART_InlineErrorTemplatePanel ToolTip"> |
||||
|
<Setter Property="BorderBrush" Value="{DynamicResource SystemControlErrorTextForegroundBrush}" /> |
||||
|
</Style> |
||||
|
<Style Selector="Panel#PART_InlineErrorTemplatePanel ToolTip TextBlock"> |
||||
|
<Setter Property="TextWrapping" Value="Wrap" /> |
||||
|
</Style> |
||||
|
</Panel.Styles> |
||||
|
<ToolTip.Tip> |
||||
|
<ItemsControl Items="{Binding}" /> |
||||
|
</ToolTip.Tip> |
||||
|
<Path Width="14" |
||||
|
Height="14" |
||||
|
Data="M14,7 A7,7 0 0,0 0,7 M0,7 A7,7 0 1,0 14,7 M7,3l0,5 M7,9l0,2" |
||||
|
Stroke="{DynamicResource SystemControlErrorTextForegroundBrush}" |
||||
|
StrokeThickness="2" /> |
||||
|
</Panel> |
||||
|
</DataTemplate> |
||||
|
<ControlTemplate x:Key="TooltipDataValidationContentTemplate" TargetType="DataValidationErrors"> |
||||
|
<DockPanel LastChildFill="True"> |
||||
|
<ContentControl Content="{Binding (DataValidationErrors.Errors)}" |
||||
|
ContentTemplate="{TemplateBinding ErrorTemplate}" |
||||
|
DataContext="{TemplateBinding Owner}" |
||||
|
DockPanel.Dock="Right" |
||||
|
IsVisible="{Binding (DataValidationErrors.HasErrors)}" /> |
||||
|
<ContentPresenter Name="PART_ContentPresenter" |
||||
|
Padding="{TemplateBinding Padding}" |
||||
|
Background="{TemplateBinding Background}" |
||||
|
BorderBrush="{TemplateBinding BorderBrush}" |
||||
|
BorderThickness="{TemplateBinding BorderThickness}" |
||||
|
Content="{TemplateBinding Content}" |
||||
|
ContentTemplate="{TemplateBinding ContentTemplate}" /> |
||||
|
</DockPanel> |
||||
|
</ControlTemplate> |
||||
|
</Style.Resources> |
||||
|
|
||||
|
<Setter Property="Template" Value="{StaticResource InlineDataValidationContentTemplate}" /> |
||||
|
<Setter Property="ErrorTemplate" Value="{StaticResource InlineDataValidationErrorTemplate}" /> |
||||
|
</Style> |
||||
|
</Styles> |
||||
|
|||||
Loading…
Reference in new issue