编辑器不支持在UWP Xamarin的listview中滚动

时间:2016-08-24 10:31:36

标签: windows xamarin uwp uwp-xaml

ListView中不支持滚动的编辑器

滚动支持android和ios但我正在解决UWP问题

 <ListView 
         x:Name="listProjects" 
         HasUnevenRows="true"
         SeparatorVisibility="None"
         ItemsSource="{Binding Feedbacks}"
         HorizontalOptions="FillAndExpand" 
         ItemTapped="Handle_ItemTapped">

        <ListView.ItemTemplate>
          <DataTemplate>
             <ViewCell>
            <StackLayout  Padding="15,15,15,15" BackgroundColor="Transparent">
               <Editor HeightRequest="50" FontSize="Small"/>
                </StackLayout>
             </ViewCell>
          </DataTemplate>
            </ListView.ItemTemplate>
 </ListView>

1 个答案:

答案 0 :(得分:0)

  

滚动支持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>

<强>截图: enter image description here

检查我已完成的示例here