【问题标题】:How to bind property to another object inside BindableLayout.ItemsSource如何将属性绑定到 BindableLayout.ItemsSource 中的另一个对象
【发布时间】:2020-12-07 11:35:47
【问题描述】:

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

【问题讨论】:

    标签: c# mvvm xamarin.forms data-binding


    【解决方案1】:

    您可以在 xaml 中设置绑定路径

    在xml中

    <?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。

    【讨论】:

      猜你喜欢
      • 2020-06-22
      • 1970-01-01
      • 1970-01-01
      • 2021-09-13
      • 2018-04-01
      • 1970-01-01
      • 2010-11-14
      • 1970-01-01
      • 2011-05-26
      相关资源
      最近更新 更多