How to programmatically click the picker button

영훈 정 281 Reputation points
2022-11-09T05:58:39.437+00:00

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.

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

Accepted answer
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 68,016 Reputation points Microsoft Vendor
    2022-11-10T06:21:00.573+00:00

    Hello,

    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 5.0.0.2196

       <Picker x:Name="picker"  
              >  
                   <Picker.ItemsSource>  
                       <x:Array Type="{x:Type x:String}">  
                           <x:String>Baboon</x:String>  
                           <x:String>Capuchin Monkey</x:String>  
                             
                       </x:Array>  
                   </Picker.ItemsSource>  
               </Picker>  
         
              <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