【发布时间】: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>
我想将Name 和Price 绑定到一个标签上。
【问题讨论】: