Ticket Q428449
Visible to All Users

LookupEdit Popup Height Too High

created 13 years ago

I'm using your dxg:LookUpEdit component in a UserControl. My problem is that the popup rectangle is always much bigger that the contents of the items in the PopupContentTemplate. I can't seem to find a property that governs this and I don't understand why it wouldn't default to only the height of its contents.

Thanks
Mark

Answers

created 12 years ago (modified 12 years ago)

Hello all,

I also encountered this problem and wanted to share a more convenient solution for this problem, one that uses Attached Behaviors.

Add this class to your project:

C#
public static class LookUpEditPopupSizeBehavior { public static DependencyProperty AllowAutoPopupSizeProperty; /// <summary> /// Initializes the <see ref="LookUpEditPopupSizeBehavior" /> class. /// </summary> static LookUpEditPopupSizeBehavior() { AllowAutoPopupSizeProperty = DependencyProperty.RegisterAttached("AllowAutoPopupSize", typeof(bool), typeof(LookUpEditPopupSizeBehavior), new FrameworkPropertyMetadata(OnAllowAutoPopupSize)); } public static void SetAllowAutoPopupSize(LookUpEditBase editor, bool value) { editor.SetValue(AllowAutoPopupSizeProperty, value); } public static bool GetAllowAutoPopupSize(LookUpEditBase editor) { return (bool)editor.GetValue(AllowAutoPopupSizeProperty); } private static void OnAllowAutoPopupSize(DependencyObject d, DependencyPropertyChangedEventArgs e) { LookUpEditBase editor = d as LookUpEditBase; bool oldValue = (bool)e.OldValue; bool newValue = (bool)e.NewValue; if (oldValue) { editor.PopupOpened -= AdjustPopupSize; } if (newValue) { editor.PopupOpened += AdjustPopupSize; } } private static void AdjustPopupSize(object sender, RoutedEventArgs e) { LookUpEditBase editor = sender as LookUpEditBase; FrameworkElement control = LookUpEditHelper.GetVisualClient(editor).InnerEditor; double height = Math.Min (control.DesiredSize.Height + 3, 300); editor.PopupMinHeight = height; editor.PopupHeight = height; } }

To use, simple write (in a style in my case):

XAML
<Setter Property="myNS:LookUpEditPopupSizeBehavior.AllowAutoPopupSize" Value="True" />

Hope you find this useful.

Regards,
Shahaf.

P.S.

The above solution has a bug where the height of the popup is not correctly set when changing the LookUpEdit ItemsSource property. For a fix see this post: http://www.devexpress.com/Support/Center/p/Q445787.aspx

    Comments (1)
    DevExpress Support Team 12 years ago

      Hi Shahaf,
      Thank you for sharing your results! You are right, this approach is very useful since it allows enabling this functionality by setting only one property.
      Please do not hesitate to contact us if you have any further difficulty. We will be happy to help you!
      Thanks

      created 13 years ago (modified 13 years ago)

      Hi Mark,
      Thank you for your inquiry. This behavior is caused by the fact that we do not resize the LookUpEdit's popup automatically based on the popup's content. To achieve this goal, I suggest you set the PopupMinHeight property based on popup content's height. You can do this in the PopupOpened event handler.
      If you have additional questions, feel free to reactivate this thread.
      Thanks

        Comments (2)

          Thanks Ivan. Sorry for the novice follow-up but I'm in the PopupOpened event now but I can't figure out how to reference the popup content object to get it's height! As you can probably tell, I'm fairly new to WPF so any help would be appreciated.

          DevExpress Support Team 13 years ago

            Hi Mark,
            I have created a sample project that demonstrates this approach in action. Please take a moment to review it in the attachment and let me know if you need additional assistance.
            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.