This is a migrated thread and some comments may be shown as answers.

Detecting the DropDownPosition

2 Answers 72 Views
Buttons
This is a migrated thread and some comments may be shown as answers.
Jon
Top achievements
Rank 1
Jon asked on 03 Mar 2011, 01:42 PM
Hi!

Is it possible to detect the actual drop-down position of the DropDownContent?

I'm trying to set the MaxHeight according to the total hight of the host (to avoid content beeing clipped when exceeding the boundaries of the browser, and insted get the vertical scroll-bars).

Currently I'm doing this by measuring how far down the DropDown control is on the page. For example:

Point

 

 

dropDownPos = ddDropDown.TransformToVisual(null).Transform(new Point());

double DropDownMaxHeight = Application.Current.Host.Content.ActualHeight - (dropDownPos.Y + ddDropDown.ActualHeight);


This works fine, until the DropDownplacement changes from bottom to top (because we get further down on the page).

So I need a way to detect when the control chooses to display the dropdown contents above instead of below the control, so that I can calculate the proper MaxHeight of the dropdown. (And the "auto-positioning" feature is just fine, I don't want to force the dropdown above or below)

Currently, I'm adjusting the MaxHeight in the DropDownOpened event.

Thanks!

Jon

 

 

2 Answers, 1 is accepted

Sort by
0
Accepted
Tina Stancheva
Telerik team
answered on 07 Mar 2011, 03:59 PM
Hello Jon,

The automatic Position behavior that you describe happens when the popup encounters the edge of the screen. You can check the VerticalOffset of the popup to check whether the popup is positioned above or bellow its target:
verticalOffset = (sender as RadDropDownButton).FindChildByType<Popup>().RealPopup.VerticalOffset;
if(verticalOffset >0)
{
    //the popup is opened bellow its placement target
}
else
{
    //the popup is opened above its placement target
}

The (sender as RadDropDownButton).FindChildByType<Popup>() returns the Telerik Popup control wich is defined in the RadDropDownButton's Controltemplate, whilst its RealPopup property holds the System.Windows.Controls.Primitives.Popup control on which the Telerik's Popup control is cased on.

Also, since it may take a moment for the popup to update its VerticalOffset value, it is best to place your logic inside a Dispatcher in order to make sure that you are working with the updated current values.

I hope that info will help you.

Regards,
Tina Stancheva
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Jon
Top achievements
Rank 1
answered on 08 Mar 2011, 09:57 AM
Hi Tina,

Thanks, that did the trick!
And yes, the Dispatcher is necessary to get the updated values.

For the record, here's my complete code (notice that I have to remove the RealPopup property when in Silverlight.)

 

private void ddDropDown_DropDownOpened(object sender, RoutedEventArgs e)
{
    ddDropDown.Dispatcher.BeginInvoke(
        delegate()
        {
            double verticalOffset = (sender as RadDropDownButton).FindChildByType<Popup>().VerticalOffset;
            if (verticalOffset > 0)
            {
                //the popup is opened below its placement target
            }
            else
            {
                //the popup is opened above its placement target
            }
        }
    );
}


Cheers,
Jon
Tags
Buttons
Asked by
Jon
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
Jon
Top achievements
Rank 1
Share this question
or