We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Adding x:DataType to DataTemplate crashes the app

I have a listview (SfListView version: 16.4.0.53) bound to a list of objects. In order to improve binding performance I added x:DataType to the item DataTemplate but this causes the app to crash with the following exception:

ItemGenerator.CreateTemplate (Syncfusion.ListView.XForms.ListViewItemInfoBase item, Xamarin.Forms.DataTemplate template)
System.NullReferenceException: Object reference not set to an instance of an object

  • TypedBinding`2[TSource,TProperty].ApplyCore (System.Object sourceObject, Xamarin.Forms.BindableObject target, Xamarin.Forms.BindableProperty property, System.Boolean fromTarget)
  • TypedBinding`2[TSource,TProperty].Apply (System.Object context, Xamarin.Forms.BindableObject bindObj, Xamarin.Forms.BindableProperty targetProperty, System.Boolean fromBindingContextChanged)
  • BindableObject.ApplyBindings (System.Boolean skipBindingContext, System.Boolean fromBindingContextChanged)
  • BindableObject.SetInheritedBindingContext (Xamarin.Forms.BindableObject bindable, System.Object value)
  • Element.SetChildInheritedBindingContext (Xamarin.Forms.Element child, System.Object context)
  • Element.b__74_0 (Xamarin.Forms.BindableObject child, System.Object bc)
  • BindableObjectExtensions.PropagateBindingContext[T] (Xamarin.Forms.BindableObject self, System.Collections.Generic.IList`1[T] children, System.Action`2[T1,T2] setChildBindingContext)
  • Element.OnBindingContextChanged ()
  • View.OnBindingContextChanged ()
  • BindableObject.BindingContextPropertyChanged (Xamarin.Forms.BindableObject bindable, System.Object oldvalue, System.Object newvalue)
  • BindableObject.SetValueActual (Xamarin.Forms.BindableProperty property, Xamarin.Forms.BindableObject+BindablePropertyContext context, System.Object value, System.Boolean currentlyApplying, Xamarin.Forms.Internals.SetValueFlags attributes, System.Boolean silent)
  • BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, Xamarin.Forms.Internals.SetValueFlags attributes, Xamarin.Forms.BindableObject+SetValuePrivateFlags privateAttributes)
  • BindableObject.SetValue (Xamarin.Forms.BindableProperty property, System.Object value, System.Boolean fromStyle, System.Boolean checkAccess)
  • BindableObject.SetValue (Xamarin.Forms.BindableProperty property, System.Object value)
  • BindableObject.set_BindingContext (System.Object value)
  • ItemGenerator.CreateTemplate (Syncfusion.ListView.XForms.ListViewItemInfoBase item, Xamarin.Forms.DataTemplate template)
  • ItemGenerator.UpdateTemplate (Syncfusion.ListView.XForms.ListViewItemInfoBase itemInfo, Xamarin.Forms.DataTemplate template)
  • ItemGenerator.UpdateRecordItem (Syncfusion.ListView.XForms.ListViewItemInfoBase itemInfo, System.Int32 rowindex, System.Object data, Xamarin.Forms.DataTemplate template)
  • ItemGenerator.CreateRecordItem (System.Int32 rowindex, System.Object data, Xamarin.Forms.DataTemplate template)
  • LayoutBase.CreateListViewItem (System.Int32 itemIndex, Syncfusion.ListView.XForms.ItemType itemType, System.Object itemData, Xamarin.Forms.DataTemplate template)
  • LinearLayout.EnsureItems (Syncfusion.GridCommon.ScrollAxis.VisibleLinesCollection visibleLines)
  • VisualContainer.EnsureItems ()
  • VisualContainer.OnSizeAllocated (System.Double width, System.Double height)
  • VisualElement.SizeAllocated (System.Double width, System.Double height)
  • Layout.ForceLayout ()
  • SfListViewHelper.InvalidateForceLayout (Xamarin.Forms.Layout`1[T] view)
  • SfListView.RefreshView (System.Boolean canResetRowHeight)
  • SfListView.RefreshView ()
  • SfListView.OnItemsSourceChanged (Xamarin.Forms.BindableObject bindable, System.Object oldValue, System.Object newValue)
  • BindableObject.SetValueActual (Xamarin.Forms.BindableProperty property, Xamarin.Forms.BindableObject+BindablePropertyContext context, System.Object value, System.Boolean currentlyApplying, Xamarin.Forms.Internals.SetValueFlags attributes, System.Boolean silent)
  • BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, Xamarin.Forms.Internals.SetValueFlags attributes, Xamarin.Forms.BindableObject+SetValuePrivateFlags privateAttributes)
  • BindableObject.SetValue (Xamarin.Forms.BindableProperty property, System.Object value, System.Boolean fromStyle, System.Boolean checkAccess)
  • BindableObject.SetValue (Xamarin.Forms.BindableProperty property, System.Object value)
  • SfListView.set_ItemsSource (System.Object value)



  • 4 Replies

    GP Gnana Priya Namasivayam Syncfusion Team March 2, 2019 12:36 AM UTC

    Hi Giorgi, 
     
     
    Thanks for using Syncfusion support. 
     
    Can you please explain the how you are trying to implement ItemTemplate with x:DataType in your application and share your xaml code by explaining the use case of your application in detail. We are not clear with your query , can you please share some more details along with Xamarin forms version so that we can able to analyze the issue better at our end. 
     
    Regards, 
    Gnana Priya N 



    GD Giorgi Dalakishvili March 2, 2019 09:20 PM UTC

    The ItemTemplate for my listview looks like this:

                    <xForms:SfListView.ItemTemplate>
                        <DataTemplate>
                            <StackLayout Orientation="Horizontal" Padding="30,0,0,0" VerticalOptions="Center">
                                <Label Text="{Binding Title}" HorizontalOptions="Start" TextColor="{Binding IsPlayed, Converter={StaticResource PlayedColorConverter}}" FontAttributes="Bold" VerticalOptions="Center" />
                                <Label Text="{Binding Duration}" HorizontalOptions="EndAndExpand" MinimumWidthRequest="50" TextColor="White" FontAttributes="Bold" VerticalOptions="Center" />
                                <Image Source="{Binding IsDownloaded, Converter={StaticResource LectureIconConverter}}" VerticalOptions="Center">
                                    <Image.GestureRecognizers>
                                        <TapGestureRecognizer Command="{Binding DownloadCommand, Source={x:Reference Page}}" CommandParameter="{Binding LectureId}"></TapGestureRecognizer>
                                    </Image.GestureRecognizers>
                                </Image>
                            </StackLayout>
                        </DataTemplate>
                    </xForms:SfListView.ItemTemplate>

    I want to use Compiled Bindings in order to improve binding performance so I add x:DataType but it causes crash at runtime
    x (x)


    SR Sangeetha Raju Syncfusion Team March 4, 2019 01:37 PM UTC

    Hi Giorgi,

     

    Currently we are analyzing your queries. We will check and let you know the details in three business days (March 7, 2019). We will appreciate your patience until then.

     

    Regards, 

    Sangeetha Raju.



    GP Gnana Priya Namasivayam Syncfusion Team March 8, 2019 03:38 AM UTC

    Hi Giorgi, 
     
    We have checked the reported query from our side. We have prepared the sample based on your requirement by adding x:datatype as model to the ItemTemplate and based on that binded ItemsSource property added as static in ViewModel.cs which works fine and SfListView loaded properly. We attached the sample for your reference, please find the sample from following. 
     
     
    Please let us know whether sample meets your requirement. 
     
    Regards, 
    Gnana Priya N 


    Loader.
    Live Chat Icon For mobile
    Up arrow icon