在 android 和 ios 中都支持滚动,但我遇到了 UWP 问题
是的,目前编辑器控件在 UWP 应用程序中不能作为 ViewVell 的子控件滚动,我看到您在 bugzilla 站点中创建了一个错误:https://bugzilla.xamarin.com/show_bug.cgi?id=43660
这里的解决方法是自定义 ViewCell 并在每个平台上创建自定义渲染器。对于 UWP,使用 RichEditBox 控件或其他可滚动控件作为替代。
请看文档:Customizing a ViewCell
XAML:
<ListView.ItemTemplate>
<DataTemplate>
<local:NativeCell Name="{Binding Name}" Category="{Binding Category}" />
</DataTemplate>
</ListView.ItemTemplate>
NativeCell:
public class NativeCell : ViewCell
{
public static readonly BindableProperty NameProperty =
BindableProperty.Create("Name", typeof(string), typeof(NativeCell), "");
public string Name
{
get { return (string)GetValue(NameProperty); }
set { SetValue(NameProperty, value); }
}
public static readonly BindableProperty CategoryProperty =
BindableProperty.Create("Category", typeof(string), typeof(NativeCell), "");
public string Category
{
get { return (string)GetValue(CategoryProperty); }
set { SetValue(CategoryProperty, value); }
}
}
为 UWP 定制的渲染:
using WorkingWithListview;
using WorkingWithListview.UWP.Renderers;
using Xamarin.Forms;
using Xamarin.Forms.Platform.UWP;
[assembly: ExportRenderer(typeof(NativeCell), typeof(NativeUWPCellRenderer))]
namespace WorkingWithListview.UWP.Renderers
{
public class NativeUWPCellRenderer : ViewCellRenderer
{
public override Windows.UI.Xaml.DataTemplate GetTemplate(Cell cell)
{
return App.Current.Resources["ListViewItemTemplate"] as Windows.UI.Xaml.DataTemplate;
}
}
}
App.xaml 中的数据模板:
<DataTemplate x:Key="ListViewItemTemplate">
<Grid Background="LightBlue">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="100" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.40*" />
<ColumnDefinition Width="0.40*"/>
<ColumnDefinition Width="0.20*" />
</Grid.ColumnDefinitions>
<RichEditBox Grid.Row="1" />
<TextBlock Grid.ColumnSpan="2" Foreground="#7F3300" FontStyle="Italic" FontSize="22" VerticalAlignment="Top" Text="{Binding Name}" />
<Line Grid.Row="2" Grid.ColumnSpan="3" X1="0" X2="1" Margin="30,20,0,0" StrokeThickness="1" Stroke="LightGray" Stretch="Fill" VerticalAlignment="Bottom" />
</Grid>
</DataTemplate>
截图:
检查我完成的样本here