Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

Reusing Usercontrol and invoke BindingContext method

$
0
0

Hi all, I have a user control [A], with a code behind method to invoke its viewmodel command :

void test()
{
    if(this.BindingContext as AViewModel !=null)
    {
        var vm = this.BindingContext as AViewModel ;
        vm.ACommand.Execute(null);
    }
}

However what should I do if I want to use this user control in other pages with different view model? I wonder is it correct to do the following?

void test()
{
    if(this.BindingContext as AViewModel !=null)
    {
        var vm = this.BindingContext as AViewModel ;
        vm.ACommand.Execute(null);
    }
    **else
    if(this.BindingContext as BViewModel !=null)
    {
        var vm = this.BindingContext as BViewModel ;
        vm.BCommand.Execute(null);
    }**
}

Thanks!


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>