Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
625
UltraGrid: Custom ValueListItemUIElement - UI automation broken
posted

I have created a subclass for ValueListItemUIElement to handle some rare exceptions that occur in a mixed WinForms/WPF environment (I have an override for InitAppearance that calls the base class and catches exceptions that occur in this call chain). This all works pretty well so far. 

However, this seems to have broken UI automation and this is probably related to the way how I create and initialize the new instances. I used a CreationFilter (IUIElementCreationFilter) and in there I have the following section:

      public void AfterCreateChildElements(UIElement parent)
        {

            switch (parent)
            {
 ...
                 case ValueListItemContainerUIElement container:
                    {
                        // replace standard ValueListItemUIElement with our custom class that catches
                        // null reference exceptions
                        var newChildElements = parent.ChildElements.Select(
                            c =>
                                {
                                    if (c is ValueListItemUIElement valueListItemUIElement)
                                    {
                                        var newValueListItemUIElement = new SafeValueListItemUIElement(
                                            container,
                                            valueListItemUIElement.ValueListItem,
                                            valueListItemUIElement.IsMruItem,
                                            valueListItemUIElement.ListIndex)
                                        {
                                            Rect = valueListItemUIElement.Rect
                                        };

                                        return newValueListItemUIElement;
                                    }

                                    return null;
                                })
                            .Where(i => i != null)
                            .ToList();

                        parent.ChildElements.Clear();
                        parent.ChildElements.AddRange(newChildElements);
                        parent.DirtyChildElements(true);
                        break;
                    }

I assume something is missing in my initialization of the new instances. In the debugger I noticed that the AccessibilityInstance of the new entities has an empty (0,0,0,0) BoundingRectangle and Bounds property.

Does anyone have any clue what might be missing here?

Parents
  • 1560
    Offline posted

    Hello,

    I have created a small sample trying to reproduce the described behavior. I used the provided snippet, however since I'm not sure what is the implementation of the mentioned custom class and the data in the value list, I modified it a little bit in order to check whether the item value is null instead of the item itself. On my side, the only issue I'm seeing is that even after some child is removed the parent container size remains the same. If this is the " broken UI " you mentioned, I could say that the reason for such behavior is because in the AfterCreateChildElements method the container of the drop-down is already calculated. The best suggestion is not to add a null value or items to the ValueList when it is created and there to perform some kind of check if it is possible. This way there would be no need for CreationFilter.

    Otherwise, attached you will find my sample for your reference. Please test it on your side and let me know how it behaves. If this is not an accurate demonstration of what you are trying to achieve please feel free to modify it and send it back to me along with steps to reproduce. Alternatively, if the behavior cannot be replicated please feel free to provide your own sample. Remove any external dependencies and code that is not directly related to the issue, zip your application and attach it in this case.

    Having a working sample on my side, which I can debug, is going to be very helpful in finding the root cause of this behavior.

    Thank you for your cooperation.

    Looking forward to hearing from you.

    Regards,

     

    Teodosia Hristodorova

    Associate Software Developer

    3731.UltraGrid_ValueListItem_CreationFilter.zip

Reply Children