RadSplitButton DropDownPlacement

1 Answer 93 Views
Buttons
ClausDC
Top achievements
Rank 1
Iron
Iron
ClausDC asked on 02 May 2022, 10:16 AM

Is it possible to let the drop down content open with bottom right aligned placement? Currently, when setting the drop down placement to "Bottom", it opens left aligned relative to the the split button.

Please see attachment for how it should look

 

1 Answer, 1 is accepted

Sort by
1
Accepted
Stenly
Telerik team
answered on 05 May 2022, 08:03 AM

Hello Claus,

To achieve the desired result, you could subscribe to the DropDownOpened event of the RadSplitButton control. In it, retrieve the Popup element via the ChildrenOfType extension method. After that, modify its HorizontalOffset property, by calculating the ActualWidth property of both the RadSplitButton instance and that of its child element's ActualWidth.

The following code snippet shows this approach's implementation:

private void RadSplitButton_DropDownOpened(object sender, RoutedEventArgs e)
{
    var splitButton = ((RadSplitButton)sender);
    var popup = splitButton.ChildrenOfType<Popup>().FirstOrDefault();

    if (popup != null)
    {
        var popupChild = popup.Child as Grid;
        popup.HorizontalOffset = this.button.ActualWidth - popupChild.ActualWidth;
    }
}

The produced result is as follows:

In conclusion, could you give this approach a try?

Regards,
Stenly
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

ClausDC
Top achievements
Rank 1
Iron
Iron
commented on 09 May 2022, 06:44 AM

should be
splitButton.ActualWidth - popupChild.ActualWidth;
in the last line. Other than that it works, thanks!
Stenly
Telerik team
commented on 09 May 2022, 07:57 AM

I am happy to hear that the proposed approach is a suitable solution to this matter.

Regarding the shared line of code, indeed, in the last line of the if conditional check, the proposed code snippet should be used instead. With this in mind, I have modified the code snippet to include this suggestion:

private void RadSplitButton_DropDownOpened(object sender, RoutedEventArgs e)
{
    var splitButton = ((RadSplitButton)sender);
    var popup = splitButton.ChildrenOfType<Popup>().FirstOrDefault();

    if (popup != null)
    {
        var popupChild = popup.Child as Grid;
        popup.HorizontalOffset = splitButton.ActualWidth - popupChild.ActualWidth;
    }
}
Tags
Buttons
Asked by
ClausDC
Top achievements
Rank 1
Iron
Iron
Answers by
Stenly
Telerik team
Share this question
or