MaterialDesignInXAML / MaterialDesignInXamlToolkit

Google's Material Design in XAML & WPF, for C# & VB.Net.
http://materialdesigninxaml.net
MIT License
15.04k stars 3.41k forks source link

Display Adorner error like MahApps does #1626

Closed gitjsdr26 closed 2 years ago

gitjsdr26 commented 4 years ago

Dear All, Is it possible to display TextBox Adorner error like MahApps does ? See https://github.com/MahApps/MahApps.Metro/issues/3320

Thank you Best regards

Keboo commented 4 years ago

@gitjsdr26 sorry for the long delay on this. I am not sure exactly what is being asked here. This library does support validation it appears different than the default MahApps validation because it is designed to confirm to Google's material design specification.

You can see an example in the demo app

image

gitjsdr26 commented 4 years ago

@Keboo , Your are welcome and thank you for your reply. I was wondering if it was possible for my purpose to display this kind of MahApps Adorner while using Material Design MahAppsAdronerLike

Best regards.

Keboo commented 4 years ago

Hi @gitjsdr26 if you would prefer to turn off the material design validation template and switch back to the MahApps one, you can do something like this:

 <TextBox Validation.ErrorTemplate="{StaticResource MahApps.Templates.ValidationError}">
gitjsdr26 commented 4 years ago

Thank you @Keboo . I tried this but I get errors Resource not found despite having added <Source="pack://application:,,,/MahApps.Metro;component/Styles/ValidationErrorTemplate.xaml" /> in my ResourceDictionary

Defining a new style also doesn't work

<Style x:Key="CustomTextBlock" BasedOn="{StaticResource MaterialDesignButtonTextBlock}" TargetType="{x:Type TextBlock}">
    <Setter Property="FontSize" Value="16"/>
    <Setter Property="FontWeight" Value="Regular"/>
    <Setter Property="Validation.ErrorTemplate" Value="{DynamicResource MahApps.Templates.ValidationError}" />
</Style>

Do you have an idea ? Best regards

Keboo commented 4 years ago

@gitjsdr26 it looks like you are trying to define the style on TextBlock (which is readonly), and not on TextBox

gitjsdr26 commented 4 years ago

Hi @Keboo , You are right. I corrected my application ResourceDictionary like

<!-- TextBox -->
<Style x:Key="CustomTextBox" BasedOn="{StaticResource MaterialDesignTextBox}" TargetType="{x:Type TextBox}">
    <Setter Property="Validation.ErrorTemplate" Value="{StaticResource MahApps.Templates.ValidationError}" />
</Style>

then my TextBox <TextBox Margin="0 0 0 0" Text="{Binding PCInterFrameDelay, NotifyOnTargetUpdated=True, NotifyOnSourceUpdated=True, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnDataErrors=True}" MaxLength="3" Style="{StaticResource CustomTextBox}"/>

But when calling the error template, I get the error System.InvalidOperationException : ''{DependencyProperty.UnsetValue}' n'est pas une valeur valide pour la propriété 'ErrorTemplate'.'

Keboo commented 2 years ago

Sorry for dropping the ball on this one. Based on the error message, it looks like it is failing to resolve the error template.

gitjsdr26 commented 2 years ago

It's now working. Thank you