问题描述
我有BindableLayout,它绑定到viewmodel属性(实际上是一个子类),但是在此布局中,我试图将Command绑定到VM的另一个属性。在这种情况下,如何指定要绑定的属性?
XAML代码:
<Grid BindableLayout.ItemsSource="{Binding ActualValues}"
Grid.Column="0"
Grid.ColumnSpan="2"
Grid.Row="0">
<BindableLayout.ItemTemplate>
<DataTemplate>
<Frame Margin="{Binding Margin}">
<Entry TabIndex="{Binding Id}"
Text="{Binding Value}"
Placeholder="{Binding Placeholder}"
Style="{StaticResource EntryStyle}">
<Entry.Behaviors>
<behaviors:EntryCompletedBehavior Command="{Binding EntryCompletedCommand}"/>
</Entry.Behaviors>
</Entry>
</Frame>
</DataTemplate>
</BindableLayout.ItemTemplate>
</Grid>
解决方法
您可以在xaml中设置绑定路径
xaml
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:local="clr-namespace:xxx"
x:Class="xxx.MainPage"
x:Name="page" // set name of ContentPage
>
Command="{Binding Source={x:Reference page},Path=BindingContext.xxxCommand}"
xxxCommand 是在VM中定义的ICommand。