【发布时间】:2017-10-06 16:48:34
【问题描述】:
我有一个带有ListView 的视图。现在我为这个ListView 切换到custom renderer(顺便说一下ViewCell 的自定义渲染器)。如果我在模拟器(iOS、Android)中启动应用程序,我会收到以下异常:
Xamarin.Forms.Xaml.XamlParseException:位置 12:13。无法分配属性“CachingStrategy”:属性不存在,或者不可分配,或者值和属性之间的类型不匹配
如果我删除CachingStrategy,一切似乎都正常。这是我的代码:
查看,ListView 所在的位置:
<StackLayout xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MyApp.Views.SomeView"
xmlns:customViews="clr-namespace:MyApp.Views;assembly=MyApp"
xmlns:renderer="clr-namespace:MyApp.CustomRenderers;assembly=MyApp"
VerticalOptions="FillAndExpand">
<renderer:CustomListView x:Name="SomeList"
SeparatorColor="{StaticResource PrimaryLight}"
HasUnevenRows="True"
CachingStrategy="RecycleElement"
IsGroupingEnabled="True"
GroupDisplayBinding="{Binding Key}"
IsPullToRefreshEnabled="True"
RefreshCommand="{Binding LoadDocumentsCommand}"
IsRefreshing="{Binding IsBusy, Mode=OneWay}">
<ListView.GroupHeaderTemplate>
<DataTemplate>
<customViews:GroupingHeader/>
</DataTemplate>
</ListView.GroupHeaderTemplate>
<ListView.ItemTemplate>
<DataTemplate>
<customViews:MyListItem Clicked="Item_Clicked"/>
</DataTemplate>
</ListView.ItemTemplate>
</renderer:CustomListView>
</StackLayout>
CustomListView
namespace MyApp.CustomRenderers
{
public class CustomListView : ListView
{
}
}
CustomListViewRenderer
[assembly: ExportRenderer(typeof(MyApp.CustomRenderers.CustomListView), typeof(MyApp.iOS.CustomRenderers.CustomListViewRenderer))]
namespace MyApp.iOS.CustomRenderers
{
public class CustomListViewRenderer : ListViewRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<ListView> e)
{
base.OnElementChanged(e);
if (this.Control != null)
{
var listView = (UITableView)this.Control;
if (listView != null)
{
listView.SeparatorInset = UIEdgeInsets.Zero;
}
}
}
}
}
我应该复制属性还是需要不同的构造函数?
【问题讨论】:
标签: c# listview xamarin xamarin.forms