Ticket Q445787
Visible to All Users

LookUpEdit Popup resize problem

created 12 years ago

Hello,

Using the solution I suggeste in this post: http://www.devexpress.com/Support/Center/Question/Details/Q428449, I encountered a problem calculating the desired height of the grid that I was unable to solve.

Please see attached file for sample.
In this sample there is a LookUpEdit that displays a list of Person objects. At this point, the height of the popup is calculated correctly and three rows are visible. After the the popup is open for the first time, click on the toggle button. This changes the items to be displayed in the popup. Once again, opening the popup shows the current height, displaying the only row in the collection.
However, clicking on the toggle button again, changing again the ItemsSource, doesn't change the height of the popup, and it remain in the previous height. I noticed, that for some reason, the DesiredSize of the grid retain the previous values (when it displayed a single row).

I tried calling grid.Measure, hoping it will calculate the desired size, but it didn't work. Calling InvalidateMeasure, InvalidateArrange and\or UpdateLayout had no effect as well.

Can you help finding out what is wrong with my code?

Thanks,
Shahaf.

Answers

created 12 years ago (modified 12 years ago)

Hi Shahaf,
Thank you for your inquiry and providing the sample project. The cause of this issue is that you do not reset the PopupHeight property. I suggest you do this in the PopupClosed event setter in the following manner:

C#
editor.PopupOpened += AdjustPopupSize; editor.PopupClosed += OnPopupClosed; private static void AdjustPopupSize(object sender, RoutedEventArgs e) { LookUpEditBase editor = sender as LookUpEditBase; FrameworkElement control = LookUpEditHelper.GetVisualClient(editor).InnerEditor; Dispatcher.CurrentDispatcher.BeginInvoke(new Action(() => { double height = Math.Min(control.DesiredSize.Height + 3, 300); editor.PopupMinHeight = height; editor.PopupHeight = height; }), DispatcherPriority.Render); } private static void OnPopupClosed(object sender, RoutedEventArgs e) { LookUpEditBase editor = sender as LookUpEditBase; editor.PopupHeight = 300; editor.PopupMinHeight = 300; }

Please let me know if you need additional assistance.
Thanks

    Comments (2)

      Hi Ivan,
      Thank you for your answer. It works perfectly.
      Is there a way to avoid the small flicker the popup sometimes has when its height is being adjusted?
      Regards,
      Shahaf.

      DevExpress Support Team 12 years ago

        I am afraid the current approach does not allow you to completely disable this flickering, since it is necessary to know the DesiredSize property of the grid. However, you can significantly reduce this effect.
        For this, change the PopupHeight property only if the editor's ItemsSource has been changed:

        C#
        static int OldItemsCount; static void editor_PopupOpening(object sender, OpenPopupEventArgs e) { LookUpEditBase editor = sender as LookUpEditBase; int newItemsCount = ((IList)editor.ItemsSource).Count; if(newItemsCount > OldItemsCount) { editor.PopupHeight = 300; editor.PopupMinHeight = 300; } OldItemsCount = newItemsCount; } private static void AdjustPopupSize(object sender, RoutedEventArgs e) { LookUpEditBase editor = sender as LookUpEditBase; FrameworkElement control = LookUpEditHelper.GetVisualClient(editor).InnerEditor; Dispatcher.CurrentDispatcher.BeginInvoke(new Action(() => { double height = Math.Min(control.DesiredSize.Height + 3, 300); editor.PopupMinHeight = height; editor.PopupHeight = height; }), DispatcherPriority.Render); }

        I have researched this issue once again and found another solution for you. You can implement this functionality at the GridControl level. For this, create a GridControl class descendant and override its MeasureOverride method. In this method, call the base.MeasureOverride method with the max required height and set the PopupHeight and PopupMaxHeight properties in the following manner:

        C#
        public class MyGridControl: GridControl { protected override System.Windows.Size MeasureOverride(System.Windows.Size constraint) { Size fakeSize = new Size(double.PositiveInfinity, 300); // 300 - max height Size desiredSize = base.MeasureOverride(fakeSize); ((LookUpEditBase)PopupBaseEdit.GetOwnerEdit(this)).PopupHeight = desiredSize.Height + 3; ((LookUpEditBase)PopupBaseEdit.GetOwnerEdit(this)).PopupMaxHeight = desiredSize.Height + 3; return desiredSize; } }

        I have changed your sample to demonstrate this approach in action. Please take a moment to review it in the attachment.
        Thanks

        Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

        Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.