问题描述
我正在尝试在 xamarin 中换行。我希望在描述和以“创建日期:”开始的新文本之间换行:
<ListView ItemsSource="{Binding Expenses}" HasUnevenRows="True"
SeparatorColor="Gray" ItemSelected="OnExpenseSelected">
<ListView.ItemTemplate>
<DataTemplate>
<ImageCell ImageSource="{Binding ExpenseImage}"
Text="{Binding FullName}"
Detail="{Binding MoreDetail}"
DetailColor="Black"
TextColor="Blue">
<ImageCell.ContextActions>
<MenuItem Text="Delete Expense"
IsDestructive="true"
Command="{Binding Source={x:Reference mainPage},Path=viewmodel.DeleteExpenseCommand}"
CommandParameter="{Binding .}"
/>
</ImageCell.ContextActions>
</ImageCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
这是我目前在 c# 中的代码
public string MoreDetail
{
get { return string.Format("{0}" + "\r\n" + "Date Created: {1}",Summary,TodaysDate); }
}
解决方法
似乎 Detail
属性不支持 ImageCell
的多行文本(包括 TextCell
)。
所以你可以使用网格来实现效果:
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.View>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="4*"/>
</Grid.ColumnDefinitions>
<Image Source="{Binding ExpenseImage}" Grid.Row="0" Grid.Column="0" Grid.RowSpan="2"/>
<Label Text="{Binding FullName}" TextColor="Blue" Grid.Row="0" Grid.Column="1"/>
<Label Text="{Binding MoreDetail}" TextColor="Black" Grid.Row="1" Grid.Column="1"/>
</Grid>
</ViewCell.View>
<ViewCell.ContextActions>
<MenuItem Text="Delete Expense"
IsDestructive="true"
Command="{Binding Source={x:Reference mainPage},Path=ViewModel.DeleteExpenseCommand}"
CommandParameter="{Binding .}"
/>
</ViewCell.ContextActions>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>