How to pass a Control in MAUI

Jassim Al Rahma 1,521 Reputation points
2022-10-01T15:24:01.373+00:00

Hi,

I have this method:

async void AnimateGoTo(ScrollView remove, ScrollView show)  

that I am using to pass ScrollView to it but now I need in some cases to pass StackLayout tso how can I change it from ScrollView to Control like below so it will accept any control?

async void AnimateGoTo(Control remove, Control show)  

Thanks,
Jassim

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
2,843 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,204 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 25,996 Reputation points Microsoft Vendor
    2022-10-03T09:52:56.46+00:00

    Hello,

    You can modify the parameters and convert the type in the AnimateGoTo method:

    async void AnimateGoTo(View removeView, View showView)// ScrollView and StackLayout both derive from View  
          {  
                //  ScrollView remove = (ScrollView)removeView;  
                StackLayout remove = (StackLayout)removeView;  
        }  
    

    Best Regards,
    Wenyan Zhang


    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.

    0 comments No comments