MaterialDesignInXAML / MaterialDesignInXamlToolkit

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

Problem with UI for Textbox Validation #3250

Open iltan987 opened 1 year ago

iltan987 commented 1 year ago

Bug explanation

I am using MainDemo.WPF in source code. In Fields page, at the end of page, there are 2 TextBoxes with validation. When text is empty, The red "Field is required" text appears and after that if you scroll, it doesn't stay where it should stay. Screenshot 2023-06-29 112022 ** Edit: Sorry for wrong screenshot

Screenshot 2023-06-29 112154 Screenshot 2023-06-29 112937

Version

4.9.0

nicolaihenriksen commented 1 year ago

Adding some detail: These two validation texts in particular are using the ValidationAssist.UsePopup=True attached property to "escape the bounds of the host control". This is the variant which seems to have the placement problem when scrolling.

ScottHaney commented 1 year ago

The problem with using the pop-up is that it also can escape the bounds of the main window. If you add an extra event handler inside of PopupEx to also update the popup's position when PlacementTarget.LayoutUpdated is called the popup will stay with the element when the scrollbar is used, however, it will also show outside of the window bounds when you scroll the element off screen (see the below screen shot where the "Field is Required" text follows the elements off the bottom of the window but the popup is still showing).

Screen Shot 2023-08-15 at 2 02 35 PM

From looking at the microsoft docs on popups they say that:

For security reasons, a Popup cannot be hidden by the edge of a screen

So my guess is there isn't really a great way to handle this one. Probably the best hack would be to have the popup follow the element when scrolling and then add some code to detect when the popup bounds are either completely inside the main window or are not completely inside the main window and then open/close the popup based on that. It would be kind of hacky because you wouldn't have the ability to only partially show the popup which would look weird (not to mention that for custom window shapes this would be even more inaccurate).

Also on the coding side the PlacementTarget property is owned by the Popup class and not the PopupEx class so there isn't the ability to update the event handler attachments for having the popup follow the element when that property is changed. So as long as you only set the PlacementTarget once everything will be fine but if it gets updated then the popup will no longer follow the element and the event handler to the previous PlacementTarget will not get unattached potentially creating a memory leak.

ScarletKuro commented 2 weeks ago

Hi. I was playing with the 5.1.0 demo app and noticed the problem too. The validation popup are out of the window: Validation They move when I move the window.

This problem is easily reproducible on my machine: Windows 10 PRO 22H2 19045.4780 2560x1440, 100% size of text (notice that I do not have scroll with this resolution)