如何在 BindableLayout 中绑定到 MasterPage 视图模型

雷萨

我正在尝试将我的 Command 属性绑定到我的 MasterDetailPage 视图模型中的 Command。我尝试为母版页定义 name 属性并将其设置为参考源,但它似乎没有绑定到视图模型。对于上下文,List MenuItems 是同一 Viewmodel 中的一个属性,并且 Title 绑定得很好。我相信我没有正确设置命令的源,但不确定如何修复它。另外,我正在使用 Prism,因此视图模型已经映射到 app.xaml 中。

<MasterDetailPage
x:Class="MasterDetailPrism.Views.MainPage"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:prism="http://prismlibrary.com"
prism:ViewModelLocator.AutowireViewModel="True"
x:Name="menuMasterPage">

<MasterDetailPage.Master>

    <ContentPage Title="Menu">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="225" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>


            <StackLayout Grid.Row="0" BackgroundColor="Aqua" />

            <StackLayout Grid.Row="1" BindableLayout.ItemsSource="{Binding MenuItems}">
                <BindableLayout.ItemTemplate>
                    <DataTemplate>
                        <StackLayout>
                            <Button
                                Command="{Binding NavigateAsync, Source={x:Reference menuMasterPage}}"
                                CommandParameter="{Binding NavPath}"
                                Text="{Binding Title}" />
                        </StackLayout>
                    </DataTemplate>
                </BindableLayout.ItemTemplate>
            </StackLayout>
        </Grid>

    </ContentPage>
</MasterDetailPage.Master>

雷萨

我能够弄清楚 - 我必须命名 StackLayout,然后绑定到它的根作为源,而不是 contentpage 或 masterpage。在下面的代码中,ItemsList.

        <StackLayout Grid.Row="1" BindableLayout.ItemsSource="{Binding MenuItems}" x:Name="ItemsList">
            <BindableLayout.ItemTemplate>
                <DataTemplate>
                    <StackLayout>
                        <Button
                            Command="{Binding BindingContext.NavigateAsync, Source={x:Reference ItemsList}}"
                            CommandParameter="{Binding NavPath}"
                            Text="{Binding Title}" />
                    </StackLayout>
                </DataTemplate>
            </BindableLayout.ItemTemplate>
        </StackLayout>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何在BindableLayout.ItemsSource中绑定项目索引

如何在Aurelia中从视图绑定到模型

如何在 Xamarin 中将数据从视图绑定到视图模型?

如何绑定到 C# Xamarin Forms 中的视图模型?

如何从子视图模型绑定到父视图模型中的事件

如何在WPF应用程序中绑定到子视图模型属性?

如何将视图模型中的功能绑定到swiftui中的自定义视图?

如何在多个Partail视图上应用验证,这些视图绑定到MVC中的模型的同一属性?

如何将视图的BackgroundColor属性绑定到Xamarin Forms中的视图模型?

在选项卡导航中自动保存淘汰视图模型-如何获取绑定到DOM元素的视图模型

如何在Go中定义视图模型

如何将TabControl内容的数据上下文绑定到ObservableCollection中的视图模型的实例

如何将值从TextBox绑定到Mvvm Light中的视图模型

如何将多个模型中的数据绑定到单个视图中的列表

如何将模型中的 Float 值绑定到 SwiftUI 视图中的 @Binding:Float 属性

如何使用敲除功能将多个视图模型绑定到单个页面中?

如何从视图模型将Func <T,T,T>绑定到XAML中的依赖项属性?

如何将ListBox绑定到xaml中的视图模型的成员?

如何将SwitchCell文本颜色绑定到Xamarin.Forms中的视图模型

绑定到模型或视图模型

如何将列表模型绑定到视图?

如何安全地将HTML从模型绑定到视图

Aurelia:如何将子DOM元素的视图模型绑定到父视图模型?

如何在MugenMvvm中获取与视图模型相关的视图

如何在Spring Web Flow中将多个模型绑定到单个视图?

如何在对象页面布局的块视图中将 oData 模型绑定到表?

如何在没有中间模型类的情况下将列表绑定到视图?

在Aurelia中,一个视图模型如何影响另一模型视图的绑定变量

如何在MVC(PHP)中将变量从视图传递到模型