如何解决Xamarin 表单中的换行符
我正在尝试在 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>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。