-
Notifications
You must be signed in to change notification settings - Fork 11
Avalonia. Error templates
IMPORTANT:
- For
Avalonia
versions11.0.0-rc1.1
and upper, please useReactiveValidation.Avalonia
2.0.4-pre
and upper - For
Avalonia
version0.10.xxx
useReactiveValidation.Avalonia
2.0.3
- In
Avalonia
versions11.0.0-previewX
it's impossible to use error templates from this library.
You can use default theme for error templates, but there are two reasons why it's better to include theme with templates from library:
- You want to use
Warning
level with orange brush instead of red. - You need to change localization in run-time.
There are two themes in the library:
-
FluentTheme
for Avalonia fluent theme.
-
SimpleTheme
for Avalonia simple theme. It's very basic, so it's just contains overriding basic styles.
Just include it at App.axaml
xmlns:rvThemes="clr-namespace:ReactiveValidation.Avalonia.Themes;assembly=ReactiveValidation.Avalonia"
...
<Application.Styles>
<FluentTheme />
<rvThemes:FluentTheme />
</Application.Styles>
<!-- or -->
<Application.Styles>
<default:SimpleTheme />
<rvThemes:SimpleTheme />
</Application.Styles>
Avalonia fluent theme uses SystemControlErrorTextForegroundBrush
to display error messages. This library adds SystemControlWarningTextForegroundBrush
for Warning
s. You can easily override both of them at App.axaml
:
<Application.Resources>
<SolidColorBrush x:Key="SystemControlErrorTextForegroundBrush" Color="Purple" />
<SolidColorBrush x:Key="SystemControlWarningTextForegroundBrush" Color="Green" />
</Application.Resources>
and result
For Avalonia simple theme all the same as for fluent, but brushes name are ErrorBrush
and WarningBrush
.
Avalonia.Controls.DataValidationErrors.ErrorsProperty
contains list of object
. ReactiveValidate
puts there objects of type ReactiveValidation.ValidationMessage
.
- For support run-time localization - create
DataTemplate
forReactiveValidation.ValidationMessage
type. Put insideTextBlock
or whatever you want and bind it toValidationMessage.Message
property. It's supportINotifyPropertyChanged
, so if localization changed - message will changed too. - Supporting
Warning
's a bit harder. You should check all elements atErrorsProperty
if they are allWarning
orSimpleWarning
.
You can use themes in library as sample. They are located here.