GuOrg / Gu.Wpf.ValidationScope

Form validation for WPF
MIT License
38 stars 9 forks source link

(validation:Scope.Node).Children.Count doesn't update #21

Open cbordeman opened 4 years ago

cbordeman commented 4 years ago

I have a usercontrol with this on the UserControl:

    validation:Scope.ForInputTypes="{validation:InputTypes {x:Type TextBox},
                                                           {x:Type ComboBox},
                                                           {x:Type mui:ComboBoxEx},
                                                           {x:Type mui:TextBoxEx},
                                                          ...

On the UserControl I have a TabControl. Each TabItemEx (adds Counter, a string dp) has the following:

Counter="{Binding (validation:Scope.Node).Children.Count, ElementName=CustomerSv}"

CustomerSv is a ScrollViewer inside the TabItemEx at the top level that contains all myu controls.

When I press OK, validation happens in my view model and the controls turn red as expected. However, Counter only ever shows "0" or "1". There are lots of invalid controls so the number should be > 1.

As I fix/update field values, the number goes to "0" properly, but never goes higher than "1".

cbordeman commented 4 years ago

Also, only the currently selected tab updates at all. Other tabs don't even update when selected.

JohanLarsson commented 4 years ago

This does not sound good, thanks for reporting. I'll try to repro it in a UI-test.

cbordeman commented 4 years ago

Also, I'm surrounding the contents of my tabitemex's with <AdornerDecorator>...</AdornerDecorator> so that the adorners don't disappear. This is a well known trick since TabControl seems to delete the validation adorners. I'm having no problem with that, though.

cbordeman commented 4 years ago

My mistake, I meant to say other tabs DO update, but only when selected.

JohanLarsson commented 4 years ago

I had no luck with creating a repro UI test.

I used this xaml and this test code

When the test runs it does the following:

Animation

JohanLarsson commented 4 years ago

I did some chores and released a new version https://www.nuget.org/packages/Gu.Wpf.ValidationScope/0.2.2

Please update to the latest in case the bug you reported was already fixed but not released.

cbordeman commented 4 years ago

I have isolated the bug further. It only occurs when there's an items control on the hidden tab. I have two solutions: 1) In my case the items control always contained the two same items, so I was able to remove the items control. 2) Select the tab in code when the window opens, then reselect the tab I was on immediately. When validation occurse, I can call InvalidateArrange() on the hidden tab's top level content, which usually works.

Give me a lot of time and I'll come up with a repro myself.