Как указать на MasterDetailPage в Призма - PullRequest
0 голосов
/ 11 ноября 2019

У нас было приложение, работающее на 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="&#xf6a0;" 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="&#xf224;" 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="&#xf30b;" 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="&#xf343;" 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="&#xf343;" 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>();
    }

1 Ответ

0 голосов
/ 11 ноября 2019

Неважно. Выяснили, что вызвало это из-за настроек исключений по умолчанию. Однажды установив для перехвата исключений Common Language RunTime множество для всех, обнаружил ошибку и ее отношение к формату XAML на странице сведений о мастере. Исправьте это и работайте хорошо.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...