Setting focus to a control within a Popup

I have the scenario whereby a popup is used for editing a number of different items and I want to be able to set focus to a specified control.

With Xamarin controls, the following code was provided to enable this (and worked perfectly).

private void EditOrderLinePopup_Opened(object sender, EventArgs e)

{

    // set focus to the "overriddenQuantity" field

    var nativeObject = (object)editOrderLinePopupTablet.GetType().GetRuntimeProperties().FirstOrDefault(x => x.Name.Equals("NativeObject")).GetValue(editOrderLinePopupTablet);

    var formsPopupviewContentTemplate = nativeObject.GetType().GetRuntimeFields().FirstOrDefault(x => x.Name.Equals("formsPopupViewContentTemplate")).GetValue(nativeObject);

    var txtCtrl = (formsPopupviewContentTemplate as Grid).FindByName<SfNumericTextBox>("overriddenQuantity");

    txtCtrl?.Focus();

}

Is there an equivalent code that will perform the same task using the MAUI SfNumericEntry control?


Thanks in advance.


4 Replies 1 reply marked as answer

SY Suthi Yuvaraj Syncfusion Team May 6, 2024 02:03 PM UTC

Hi Vin,

We have checked your requirement, you can access the content inside the ContentTemplate, Please refer to the below code snippet for reference. 

Code snippet:

private void popupLayout_Opened(object sender, EventArgs e)
        {
            var PopupView = popupLayout.GetType().GetRuntimeFields().FirstOrDefault(x=>x.Name == "PopupView")!.GetValue(popupLayout);
            var PopupMessageView = PopupView!.GetType().GetRuntimeFields().FirstOrDefault(x => x.Name == "PopupMessageView")!.GetValue(PopupView);
            var Content = (PopupMessageView as SfContentView)!.Content;

            if(Content is SfNumericEntry)
            {
                // content is SfNumericEntry.
            }
        }


kindly let us know if you have any concerns,

Regards,

Suthi Yuvaraj.


Attachment: MAUIPopup_b3b5d7ee.zip

Marked as answer

SY Suthi Yuvaraj Syncfusion Team May 6, 2024 02:37 PM UTC

Vin,

#Regarding MAUI SfNumericEntry control

We have SfNumericEntry, which allows you to enter numeric input and restricts the alphabetic input. Please refer to the below documentation for more reference.

UG Link:https://help.syncfusion.com/maui/numericentry/getting-started

Kindly let us know if we have misunderstood your requirement , if yes kindly share your exact requirement, what you are expecting in entry. Please let us know if you have any concerns.





VI Vin replied to Suthi Yuvaraj May 13, 2024 06:37 AM UTC

Thanks for your help.



JS Jayashree Suresh Anand Syncfusion Team May 14, 2024 10:00 AM UTC

Hi Vin,

Glad that our response did help in resolving your issue, please get back to us if you need further assistance. 

Regards,

Jayashree 


Loader.
Up arrow icon