1
votes

It appears someone else is having this issue: Validation.HasError does not trigger again if new error comes in while already true

The Validation.Error is not updating with the latest error message.

It shows the previous error not the one that actually got called last. When I log each return, the PropertyX is greater than or PropertyX is less than is returned, but it does not display that message in my tooltip. It will displays "Required".

I also found that my converter for the tooltip does not get called when the PropertyX is greater than or PropertyX is less than is returned.

Here is the validation code:

    string this[string columnName] 
    {
        get
        {
            switch(columnName)
            {
                case "Property1":
                    int output;
                    if (true == string.IsNullOrEmpty(this.Property1))
                    {
                        return "Required";
                    } else if (true == int.TryParse(this.Property1, out output))
                    {
                        return "Invalid integer";
                    } else if (true == this.Property1Int.HasValue &&
                    true == this.Property2Int.HasValue)
                    {
                        if (this.Property1Int.Value < this.Property2Int.Value)
                        {
                            return "Property2 is greater than Property1";
                        }
                    }

                    break;
                case "Property2":
                    int output;
                    if (true == string.IsNullOrEmpty(this.Property2))
                    {
                        return "Required";
                    } else if (true == int.TryParse(this.Property2, out output))
                    {
                        return "Invalid integer";
                    } else if (true == this.Property1Int.HasValue &&
                    true == this.Property2Int.HasValue)
                    {
                        if (this.Property2Int.Value > this.Property1Int.Value)
                        {
                            return "Property2 is greater than Property1";
                        }
                    }

                    break;
            };

            return string.Empty;
        }
    }

What is going on?

2
Probably it is impossible, because if it was allowed as it is in Silverlight, we would have a method which returns IEnumerable and not a single string. - vortexwolf
Can you add how you bind this error? Is it same as duplicate one? - Euphoric
Yeah I bind the same way with the Validation.HasError. - kevindaub

2 Answers

3
votes

If you are using converter as in other question, them I'm prety sure its not the best way to do things. Especialy in dynamic enviorment like WPF.

So I would recomend binding to (Validation.Errors).CurrentItem directly instead of using converter as described here:

http://joshsmithonwpf.wordpress.com/2008/10/08/binding-to-validationerrors0-without-creating-debug-spew/

0
votes

If your binding is using a converter, then this problem could be solved by removing the converter and changing the binding.

For example, say that the XAML looks like the following:

<Setter Property="ToolTip" Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors), Converter={StaticResource yourConverter}}" />

Then by updating the code to the following, you will bypass the converter:

<Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)/ErrorContent}" />

Read more about it here: https://docs.microsoft.com/en-us/dotnet/api/system.windows.data.relativesource.self?view=netframework-4.8