繁体   English   中英

如何将属性绑定到 BindableLayout.ItemsSource 中的另一个 object

[英]How to bind property to another object inside BindableLayout.ItemsSource

我有 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。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM