簡體   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