【问题标题】:Is there a way to binding two values in label - xamarin? [duplicate]有没有办法在标签中绑定两个值 - xamarin? [复制]
【发布时间】:2022-01-22 10:16:41
【问题描述】:

我有一个listview 并想从 xaml 绑定两个值。如果可能的话,我可以举个例子吗?

 <StackLayout Spacing="0" x:Name="ExchangeStack">
        <ListView x:Name="lstExchange" HasUnevenRows="True">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>
                        <ViewCell.View>
                            <Grid BackgroundColor="#454545">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="*"></RowDefinition>
                                    <RowDefinition Height="*"></RowDefinition>
                                    <RowDefinition Height="2"></RowDefinition>

                                </Grid.RowDefinitions>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="auto"></ColumnDefinition>
                                </Grid.ColumnDefinitions>
                                <Label Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" Text="{Binding Name}" XAlign="Center" YAlign="Center" TextColor="#2196F3" FontAttributes="Bold" FontSize="Medium" HorizontalOptions="CenterAndExpand"/>
                                <Label Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Text="{Binding Price, StringFormat='{0:F0} $'}" XAlign="Center" YAlign="Center" TextColor="#2bff00" FontAttributes="Bold" FontSize="Small" HorizontalOptions="CenterAndExpand"/>
                                <BoxView Color="White" HeightRequest="1" Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2"/>
                            </Grid>
                        </ViewCell.View>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>
    </StackLayout>

我想将NamePrice 绑定到一个标签上。

【问题讨论】:

    标签: c# xamarin


    【解决方案1】:

    有可能

                                <Label.Text>
                                    <MultiBinding StringFormat="{}{0} {1}">
                                        <Binding Path="Name" />
                                        <Binding Path="Price" />
                                    </MultiBinding>
                                </Label.Text>
    

    https://xamgirl.com/understanding-multi-binding-in-xamarin-forms/

    【讨论】:

      猜你喜欢
      • 2017-10-20
      • 1970-01-01
      • 2010-09-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多