How to programmatically click the picker button

영훈 정 281 Reputation points

Same as title.
How to programmatically click the picker button

I want to create a button and when the button is clicked, it will pop up as if the picker was clicked.

I tried using focus() but it doesn't work.

A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,314 questions
0 comments No comments
{count} votes

Accepted answer
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 70,961 Reputation points Microsoft Vendor


    Which platform is not working when running code?
    Could you minimize the code to just what is needed to reproduce the problem?
    I use the following code to make a test on the Android platform. If I click the button, the picker will be invoked and pop up.
    My Xamarin.Forms version is

       <Picker x:Name="picker"  
                       <x:Array Type="{x:Type x:String}">  
                           <x:String>Capuchin Monkey</x:String>  
              <Button Text="click" Clicked="Button_Clicked"></Button>  
       private void Button_Clicked(object sender, EventArgs e)  
                   picker. Focus();  

    Best Regards,

    Leon Lu

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful