How to set TextBox ErrorTemplate? #8282
Replies: 7 comments 18 replies
-
|
OK found DataValidationErrors source template here It has a nice example of it built-in showing up in the previewer! So all I need is to add this to <Style Selector="DataValidationErrors">
<Setter Property="Template" Value="{DynamicResource TooltipDataValidationContentTemplate}" />
<Setter Property="ErrorTemplate" Value="{DynamicResource TooltipDataValidationErrorTemplate}" />
</Style>Now... can I add DataValidationErrors to a ListBox to warn when the list is empty? |
Beta Was this translation helpful? Give feedback.
-
|
My first thought is adding DataValidationErrors to the template indeed. But it's not showing the error that the list is empty. For a situation where validation errors can't be displayed well in a control, like multi-control validations, is there another method of displaying validation errors? <Style Selector="ListBox">
<Setter Property="Template">
<ControlTemplate>
<DataValidationErrors>
<Border Name="border"
ClipToBounds="{TemplateBinding ClipToBounds}"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="{TemplateBinding CornerRadius}">
<ScrollViewer Name="PART_ScrollViewer"
HorizontalScrollBarVisibility="{TemplateBinding (ScrollViewer.HorizontalScrollBarVisibility)}"
VerticalScrollBarVisibility="{TemplateBinding (ScrollViewer.VerticalScrollBarVisibility)}"
AllowAutoHide="{TemplateBinding (ScrollViewer.AllowAutoHide)}">
<ItemsPresenter Name="PART_ItemsPresenter"
Items="{TemplateBinding Items}"
ItemsPanel="{TemplateBinding ItemsPanel}"
ItemTemplate="{TemplateBinding ItemTemplate}"
Margin="{TemplateBinding Padding}"
VirtualizationMode="{TemplateBinding VirtualizationMode}" />
</ScrollViewer>
</Border>
</DataValidationErrors>
</ControlTemplate>
</Setter>
</Style> |
Beta Was this translation helpful? Give feedback.
-
|
Linking documentation issue https://github.com/AvaloniaUI/Documentation/issues/278 |
Beta Was this translation helpful? Give feedback.
-
|
|
Beta Was this translation helpful? Give feedback.
-
|
Thanks for the sample, but setting validation rule in the UI is a big no-no. Validation rule goes in the ViewModel. If we create an extension method, it needs to listen to Something like... or perhaps to make a specific text block display the error Either way, accessing the |
Beta Was this translation helpful? Give feedback.
-
|
By setting this in App.xaml <Style Selector="DataValidationErrors">
<Setter Property="Template" Value="{DynamicResource TooltipDataValidationContentTemplate}" />
<Setter Property="ErrorTemplate" Value="{DynamicResource TooltipDataValidationErrorTemplate}" />
</Style>The textbox gets partially hidden when an error is displayed. <StackPanel Orientation="Horizontal">
<TextBlock Text="Rate Multiplier " VerticalAlignment="Center" />
<Grid Width="80">
<TextBox Text="{Binding Settings.Rate}" Classes="compact" />
</Grid>
</StackPanel>Version: 0.10.15 |
Beta Was this translation helpful? Give feedback.
-
|
For those who land here like me trying to get a TextBox to display the errors in a tooltip in order to stop it from affecting your layout, you can simply set the DataValidationErrors Theme property to TooltipDataValidationErrors within App.axaml or a custom axaml file with all of your styles etc... This may not be appropriate for all situations but it works for us with the controls we use with Avalonia 11-Pre6 |
Beta Was this translation helpful? Give feedback.

Uh oh!
There was an error while loading. Please reload this page.
-
How do I set the TextBox ErrorTemplate to display validation errors?
I want something that won't screw up the layout, a red exclamation mark at the right with the error as tooltip. Any sample of it done?
Beta Was this translation helpful? Give feedback.
All reactions