I have a Button on a MasterDetailPage and would like to send the MasterDetailPage to the Button Command as the CommandParameter, so that I can change the Detail Property of the MasterDetailPage from the ViewModel. Please let me know if I am approaching this all wrong.
MasterDetailPage
<?xml version="1.0" encoding="utf-8" ?>
<MasterDetailPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:XamarinApp.ViewModels"
xmlns:controls="clr-namespace:XamarinApp.Libraries.Controls"
xmlns:telerikPrimitives="clr-namespace:Telerik.XamarinForms.Primitives;assembly=Telerik.XamarinForms.Primitives"
x:Class="XamarinApp.Pages.MainPage"
Icon="hamburger.png">
<MasterDetailPage.Master>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
Title="Master Page">
<StackLayout>
<Button Text="Users" Command="{Binding GoUserAccountListPage}" CommandParameter="{Binding ThisMasterDetailPage}" />
<Button Text="Working" Command="{Binding GoWhosWorkingPage}" CommandParameter="{Binding ThisMasterDetailPage}" />
<Button Text="Calendar" />
<Button Text="People" />
<Button Text="Profile"/>
</StackLayout>
</ContentPage>
</MasterDetailPage.Master>
ViewModel
private RelayCommand<MasterDetailPage> _goUserAccountListPage;
public RelayCommand<MasterDetailPage> GoUserAccountListPage
{
get
{
return _goUserAccountListPage ?? (_goUserAccountListPage = new RelayCommand<MasterDetailPage>(masterDetail =>
{
masterDetail.Detail = NavigationService.GetNavigationPage(ViewModelLocator.UserAccountListPage);
masterDetail.IsPresented = false;
}));
}
}