Using Xaml and DataContext
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:DataAndCloudServices"
x:Class="DataAndCloudServices.MainPage" >
<StackLayout>
<!-- Command Implemented In Code Behing -->
<Button Text="Consuming Web Services Samples"
Command="{Binding NavigateCommand}"
CommandParameter="{x:Type local:YourPageTypeHere}" >
</Button>
</StackLayout>
</ContentPage>
And MainPage Code Behing, this code example is to navigate to another page using the page type as argument, you need to make "YourPageTypeHere" and reference page here.
Then implement code Behind.
using System;
using System.Windows.Input;
using Xamarin.Forms;
namespace DataAndCloudServices
{
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
NavigateCommand = new Command<Type>(
async (Type pageType) =>
{
Page page = (Page)Activator.CreateInstance(pageType);
await Navigation.PushAsync(page);
});
this.BindingContext = this;
}
public ICommand NavigateCommand { private set; get; }
}
}
Also in your App class need a Instance of NavigationPage in MainPage to Navigate (For this example)
public App ()
{
InitializeComponent();
MainPage = new NavigationPage(new MainPage());
}
It is for xamarin forms, But It is similar for WPF Projects.
Command could be changed with for WPF and Xamarin: "https://mcmap.net/q/275886/-relaycommand-parameter-passing-in-xamarin"