Unplanned
Last Updated: 16 May 2022 10:51 by ADMIN
Bobby
Created on: 13 May 2022 19:16
Category: ComboBox
Type: Feature Request
1
Add a PopupClosed event for the ComboBox

Hi Team,

Please consider adding Open/Closed event for the comboBox's popup. The validation for this is I need to perform validation if a user closes the popup without making a selection.

SelectionChanged doesn't work here, because user never selected anything. Focus events are very finnicky because of the platform differences and input modalities.

The only sane options is to add an official PopupClosed event (and you don't even need custom EventArgs).

Thank you!

Bobby

 

Workaround

For now, I am using reflection+ nonPublic|Instance BindingFields to get a reference to the private RadPopup field of the RadComboBox. With that reference, I am subscribing to PropertyChanged and watching for value changes  of the IsOpen property. 

It goes without saying, this is a very resource intensive and unofficial approach.

public partial class MainPage : ContentPage
{
    private RadPopup internalPopup;

    public MainPage()
    {
        InitializeComponent();
    }

    protected override void OnAppearing()
    {
        base.OnAppearing();

        var popup = typeof(RadComboBox).GetField("popup", BindingFlags.NonPublic | BindingFlags.Instance)?.GetValue(ComboBox1);

        if (popup is RadPopup p1)
        {
            internalPopup = p1;
            internalPopup.PropertyChanged += InternalPopup_PropertyChanged;
        }
    }

    private void InternalPopup_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
    {
        if (e.PropertyName != nameof(RadPopup.IsOpen))
            return;
        
        if (internalPopup.IsOpen)
        {
            // Popup was opened
        }
        else
        {
            // Popup was closed
        }
    }

    protected override void OnDisappearing()
    {
        if (internalPopup != null)
            internalPopup.PropertyChanged -= InternalPopup_PropertyChanged;

        base.OnDisappearing();
    }
}

1 comment
ADMIN
Didi
Posted on: 16 May 2022 10:51

Hi Bobby,

Just a follow up message.

Instead of using the reflection approach you can use the ComboBox IsDropDownOpen property. Here is the documentation: https://docs.telerik.com/devtools/xamarin/controls/combobox/combobox-key-features#dropdown-behavior 

The property indicates whether the dropdown is open/closed. IsDropDownOpen(ComboBox) == IsOpen (Popup). The property is bindable property. On property changes you can implement the logic needed.

Regards,
Didi
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.