2016-08-24 80 views
0

內的ListView編輯器,不支持滾動編輯器不支持列表視圖的UWP Xamarin

滾動支持在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> 

回答

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

+0

謝謝,富蘭克林,它的工作,但這裏我也需要設置綁定上下文到編輯器,但RichEditBox不支持文本屬性。 –

+0

@SachinKs很高興知道,這是您的問題的可接受答案嗎? ;) –

+0

是的,這是可以接受的,但在這裏我還需要將綁定上下文設置爲Text屬性以在RichEditBox中設置默認文本,有沒有辦法做到這一點? –