Skip to content

Can't compile ContentView pages with data bindings displayed on MainPage #26797

Answered by King-Taz
King-Taz asked this question in General
Discussion options

You must be logged in to vote

Your ContentPage (BindinApp.MainPage) should provide the x:DataType that corresponds to BindingContext.

The app doesn't work if x:DataType is given on MainPage as was done on Page1View and Page2View.

Instanciate your viewmodel in your <ContentPage.Resources> and give it to Page1View & Page2View

This worked, thanks! Implemented as follows (maybe there's a better way, I don't know?)

    <ContentPage.Resources>
        <ResourceDictionary>
            <local:SharedViewModel x:Key="SharedViewModel" />
        </ResourceDictionary>
    </ContentPage.Resources>

    <StackLayout>
        <local:Page1View BindingContext="{StaticResource SharedViewModel}"/>
        <local:Page2View BindingCon…

Replies: 2 comments 7 replies

Comment options

You must be logged in to vote
5 replies
@King-Taz
Comment options

@vlad0syk
Comment options

@King-Taz
Comment options

@vlad0syk
Comment options

@King-Taz
Comment options

Comment options

You must be logged in to vote
2 replies
@King-Taz
Comment options

Answer selected by King-Taz
@dartasen
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants