MaterialDesignInXamlToolkit icon indicating copy to clipboard operation
MaterialDesignInXamlToolkit copied to clipboard

Problem with UI for Textbox Validation

Open iltan987 opened this issue 2 years ago • 3 comments

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

iltan987 avatar Jun 29 '23 08:06 iltan987

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.

nicolaihenriksen avatar Jul 03 '23 10:07 nicolaihenriksen

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.

ScottHaney avatar Aug 15 '23 18:08 ScottHaney