C# 如何使用mvvmLight在Xamarin表单中将数据从ContentPage ViewModel传递到ContentView ViewModel?

C# 如何使用mvvmLight在Xamarin表单中将数据从ContentPage ViewModel传递到ContentView ViewModel?,c#,forms,xaml,xamarin,mvvm-light,C#,Forms,Xaml,Xamarin,Mvvm Light,我有一个带有一些控件的ContentPage和一个自定义导航控件(ContentView)。contentpage和navigationcontrol都有各自的ViewModels,其BindingContext设置为。现在我需要将信息从页面传递到navigationControl 我尝试的是: <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schem

我有一个带有一些控件的ContentPage和一个自定义导航控件(ContentView)。contentpage和navigationcontrol都有各自的ViewModels,其BindingContext设置为。现在我需要将信息从页面传递到navigationControl

我尝试的是:

 <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
                 xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                 xmlns:controls="clr-namespace:AuditApp.Controls;assembly=App"
                 x:Class="App.Pages.MyPage"
                 x.Name="contentpage">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="9*"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
            ...other controls...
            <controls:PageNavigationControl Grid.Row="1" Page="{Binding Page}"/>
        </Grid>
    </ContentPage>

…其他控件。。。
页面是我的navigationControl中的自定义BindingProperty。该属性可以工作,但BindingContext错误,它尝试绑定到navigationcontrol的ViewModel中的“页面”属性

如果我这样更改它:

<controls:PageNavigationControl Grid.Row="1" Page="{Binding Page}" BindingContext="{x:Relative Name=contentpage"}/>

然后它也不起作用,因为它试图绑定到ContentPage本身,而不是它的ViewModel。我需要的是将它绑定到ContentPage的ViewModel,该ViewModel具有我要从中读取的Page属性


我的方法完全错了吗?我应该使用信息中心吗?我对Xamarin表单很陌生。有谁能告诉我如何正确地做这件事吗?

对于任何在类似问题上绊倒的人,我就是这样解决的。我对这个解决方案并不完全满意,但它是有效的:

我将控件ViewModel作为页面ViewModel中的属性,并以编程方式进行设置:

NavigationViewModel=App.VmLocator.PageNavigationViewModel

在xaml中,我将自定义控件的BindingContext设置为属性:

<controls:PageNavigationControl Grid.Row="1" BindingContext="{Binding NavigationViewModel}"/>

现在我可以访问PageView模型中的控件ViewModel,并可以在那里传递所需的数据