Search code examples
c#xamlxamarinmvvmfreshmvvm

How to change the way FreshMvvm expects the page name for an entity?


I have a simple project built on FreshMvvm and there is only one entity, Contact with 2 string properties, Name and Number.

The application shows a list of contacts and when a user taps on a contact, it opens the ContactPage.xaml with the contact details.

The application works ok, but I would like to change the name of ContactPage.xaml, to ContactDetailsPage.xaml and in this case when FreshMvvm tries to find ContactPage.xaml upon opening contact details, it fails.

How can I tell to FreshMvvm to seek for ContactDetailsPage.xaml instead of ContactPage.xaml ?

ContactListPage.xaml looks like this:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="FreshMvvmDemo.Pages.ContactListPage">
    <ContentPage.Content>
        <StackLayout>
            <Label Text="{Binding MainText}" VerticalOptions="Center" HorizontalOptions="Center" />
            <ListView ItemsSource="{Binding ContactList}" SelectedItem="{Binding SelectedContact}">
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <TextCell Text="{Binding Name}" Detail="{Binding Number}"></TextCell>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>
        </StackLayout>
    </ContentPage.Content>
</ContentPage>

ContactPage.xaml looks like this:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="FreshMvvmDemo.Pages.ContactPage">
    <ContentPage.Content>
        <StackLayout>
            <Entry Text="{Binding Contact.Name}"></Entry>
            <Entry Text="{Binding Contact.Number}"></Entry>
        </StackLayout>
    </ContentPage.Content>
</ContentPage>

Solution

  • To open ContactDetailsPage.xaml instead of ContactPage.xaml I have to rename corresponding ViewModel class from ContactPageModel to ContactDetailsPageModel.

    Thanks @JackHua-MSFT for help.