У нас было приложение, работающее на MVVM без какой-либо платформы. Попробуйте скопировать очень простой MasterDetailPage, используя библиотеку Prism.
Скопируйте MasterPage из предыдущего проекта и внесите некоторые изменения.
Когда я запустил это, он появился на белой пустой странице? Есть идеи?
MasterPage.xaml
<?xml version="1.0" encoding="utf-8" ?>
<MasterDetailPage.Master>
<ContentPage Title="Master" >
<StackLayout BackgroundColor="AliceBlue">
<Grid BackgroundColor="RoyalBlue">
<BoxView HeightRequest="120" />
<Label Text="Welcome to Athlosify" TextColor="White" FontSize="Small" Margin="20, 50, 0, 0" />
</Grid>
<StackLayout Orientation="Horizontal" Margin="20,20,0,0" Spacing="10">
<ImageButton>
<ImageButton.Source>
<FontImageSource FontFamily="{StaticResource MaterialFontFamily}" Glyph="" Size="25" />
</ImageButton.Source>
</ImageButton>
<Label Text="Home" FontSize="Small" VerticalOptions="Center" TextColor="#707070"></Label>
<StackLayout.GestureRecognizers>
<TapGestureRecognizer Command="{Binding HomeCommand}" />
</StackLayout.GestureRecognizers>
</StackLayout>
<StackLayout Orientation="Horizontal" Margin="20,20,0,0" Spacing="10">
<ImageButton>
<ImageButton.Source>
<FontImageSource FontFamily="{StaticResource MaterialFontFamily}" Glyph="" Size="25" />
</ImageButton.Source>
</ImageButton>
<Label Text="Activities" FontSize="Small" VerticalOptions="Center" TextColor="#707070"></Label>
<StackLayout.GestureRecognizers>
<TapGestureRecognizer Command="{Binding ActivitiesCommand}" />
</StackLayout.GestureRecognizers>
</StackLayout>
<StackLayout Orientation="Horizontal" Margin="20,20,0,0" Spacing="10">
<ImageButton>
<ImageButton.Source>
<FontImageSource FontFamily="{StaticResource MaterialFontFamily}" Glyph="" Size="25" />
</ImageButton.Source>
</ImageButton>
<Label Text="Change Password" FontSize="Small" VerticalOptions="Center" TextColor="#707070"></Label>
<StackLayout.GestureRecognizers>
<TapGestureRecognizer Command="{Binding ChangePasswordCommand}" />
</StackLayout.GestureRecognizers>
</StackLayout>
<StackLayout Orientation="Horizontal" Margin="20,20,0,0" Spacing="10">
<ImageButton>
<ImageButton.Source>
<FontImageSource FontFamily="{StaticResource MaterialFontFamily}" Glyph="" Size="25" />
</ImageButton.Source>
</ImageButton>
<Label Text="Logout" FontSize="Small" VerticalOptions="Center" TextColor="#707070"></Label>
<StackLayout.GestureRecognizers>
<TapGestureRecognizer Command="{Binding LogoutCommand}" />
</StackLayout.GestureRecognizers>
</StackLayout>
<StackLayout Orientation="Horizontal" Margin="20,20,0,0" Spacing="10">
<ImageButton>
<ImageButton.Source>
<FontImageSource FontFamily="{StaticResource MaterialFontFamily}" Glyph="" Size="25" />
</ImageButton.Source>
</ImageButton>
<Label Text="About" FontSize="Small" VerticalOptions="Center" TextColor="#707070"></Label>
<StackLayout.GestureRecognizers>
<TapGestureRecognizer Command="{Binding AboutCommand}" />
</StackLayout.GestureRecognizers>
</StackLayout>
</StackLayout>
</ContentPage>
</MasterDetailPage.Master>
<MasterDetailPage.Detail>
<NavigationPage>
<x:Arguments>
<pages:HomePage></pages:HomePage>
</x:Arguments>
</NavigationPage>
</MasterDetailPage.Detail>
MasterViewModel.cs:
public class MasterPageViewModel : BindableBase
{
private DelegateCommand _homeCommand;
private readonly INavigationService _navigationService;
public DelegateCommand HomeCommand => _homeCommand ?? (_homeCommand = new DelegateCommand(ExecuteGoToHome));
public MasterPageViewModel(INavigationService navigationService)
{
_navigationService = navigationService;
}
async void ExecuteGoToHome()
{
await _navigationService.NavigateAsync("NavigationPage/HomePage");
}
}
App.xaml.cs:
public App() : this(null) { }
public App(IPlatformInitializer initializer) : base(initializer) { }
protected override async void OnInitialized()
{
InitializeComponent();
await NavigationService.NavigateAsync("MasterDetailPage/NavigationPage/HomePage");
}
protected override void RegisterTypes(IContainerRegistry containerRegistry)
{
containerRegistry.RegisterForNavigation<NavigationPage>();
containerRegistry.RegisterForNavigation<HomePage, HomePageViewModel>();
containerRegistry.RegisterForNavigation<MasterPage, MasterPageViewModel>();
}