When using DataTemplate, If view is created outside the DataTemplate and returns the view instance, Created View is not loaded in the Datatemplate
#4,642 创建于 2018年12月5日
仓库指标
- 星标
- (5,644 个星标)
- PR 合并指标
- (30 天内没有已合并 PR)
描述
Description
We would like to bring to your notice a bug that we encountered recently, When using DataTemplate if CustomView is created outside and returns the customView instance inside the DataTemplate, Created views are not loaded in the DataTemplate. Follow the snaps to get the differences between View is created outside the DataTemplate and returns created View instance inside the DataTemplate, with Views are created inside the DataTemplate. We suspect issue was rendering native view object, Also we have attached the tree hierarchy which clearly explains while creating view outside the DataTemplate views are not converted as NativeView. For further clarification we have attached the Android renderer snaps.
CustomView is created outside the DataTemplate and returns only instance inside the DataTemplate, You can clearly see Label is not placed in Android.View.ViewGroup
CustomView is created inside the DataTemplate, Here Label is placed in the Android.View.ViewGroup
In the above snaps difference is created view(Label) is not placed in Android.View.ViewGroup, This is our issue.
Steps to Reproduce
- Run the attached sample
- You can see the difference after View gets loaded , In RowIndex 0 and ColumnIndex 0 MyLabel view (Label View created in inside the DataTemplate) text was loaded with pink color
- At the RowIndex 0 and ColumnIndex 1 MyLabel1 view(Label View created outside the DataTeamplate and returns only View instance) was not loaded
or
ViewCell cell = new ViewCell();
cell.View = new Label() { Text = "test" };
cell.View.SetBinding(Label.TextProperty, ".");
ListView view = new ListView(ListViewCachingStrategy.RecycleElementAndDataTemplate)
{
ItemsSource = new[] { 1, 2, 3 },
ItemTemplate = new DataTemplate(() =>
{
return cell;
}),
};
return new ContentPage()
{
Content = view
};
Expected Behavior
If in case of creating views outside the DataTemplate and returns the view instance, View should get loaded.
Actual Behavior
Views are not loaded while creating view outside the DataTemplate.
Basic Information
-- Version with issue: 2.5.1.527436
- Last known good version: None
- IDE:
- Platform Target Frameworks: Xamarin forms all platforms -Android Support Library Version: Tested in 25.4.0.2
- Nuget Packages: 2.5.1.527436
- Affected Devices: All devices
Screenshots

Reproduction Link
http://www.syncfusion.com/downloads/support/directtrac/general/ze/DataTemplate_SfDataGrid347140047 This issue was reproduced in our SfListView Control also in the same scenario For your reference we have attached the SfListView sample too http://www.syncfusion.com/downloads/support/directtrac/general/ze/ListViewSample776214805
Note : If Packages are nor restored properly, You can download the Syncfusion.Xaamrin.SfDataGrid , Syncfusion.Xamarin.SfListView packages directly from nuget.org

