DataGrid LoadOnDemandRowTemplate

2 posts, 0 answers
  1. BAHADIR KORKUT
    BAHADIR KORKUT avatar
    2 posts
    Member since:
    May 2010

    Posted 24 Apr 2019 Link to this post

    I want to show total number of elements and number of currently loaded elements in the text property of a label which is inside the DataTemplate of LoadOnDemandRowTemplate.

    Setting up Text={Binding ViewModel.TotalNumberOfProducts } for the Label does't seem to work as BindingContext of the LoadOnDemandRowTemplate seems different from the pages's binding context. I couldn't figure out the correct way of implementing this with binding. Can you help?

  2. Lance | Manager Technical Support
    Admin
    Lance | Manager Technical Support avatar
    1168 posts

    Posted 24 Apr 2019 Link to this post

    Hello Bahadir,

    Correct, the BindingContect of the rendered DataTemplate is not the same as the parent. You can use one of two general Xamarin.Forms development options to get access to t value outside of the template's context:

    - Source binding

    <ContentPage x:Name="Page" ...>
      
      <DataTemplate>
        <!-- This is not in the same BindingContext of the Page, so we use an x:Reference to associate-->
        <Label Text="{Binding BindingContext.TotalNumberOfProducts, Source={x:Reference Page}"  />
      </DataTemplate>
      
    </ContentPage>


    - Use a static helper class

    <ContentPage x:Name="Page" ...>
      
      <DataTemplate>
        <!-- This is not in the same BindingContext of the Page, so we use an x:Reference to associate-->
        <Label Text="{x:Static local:HelperClass.TotalNumberOfProducts}"  />
      </DataTemplate>
      
    </ContentPage>

    If you have any further trouble, don't hesitate to open a support ticket and share the rest of the code. The UI for Xamarin engineering team will be able to directly investigate.

    Regards,
    Lance | Technical Support Engineer, Principal
    Progress Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top