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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Not able to show sfTreeview

Thread ID:

Created:

Updated:

Platform:

Replies:

150222 Dec 26,2019 09:43 PM UTC Dec 30,2019 10:15 AM UTC Xamarin.Forms 1
loading
Tags: SfTreeView
Hakan COSKUN
Asked On December 26, 2019 09:43 PM UTC

Hi I use to use Treeview, but there is a kind of output does not occur there is a ModelView there is a kind of data from treeview I do not have a half I need your half

codes


<?xml version="1.0" encoding="UTF-8"?>

<ContentPage

    xmlns="http://xamarin.com/schemas/2014/forms"

    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"

    x:Class="Gelsineve_Panel.View.KategoriTestPage"

    xmlns:sfTreeView="clr-namespace:Syncfusion.XForms.TreeView;assembly=Syncfusion.SfTreeView.XForms"

    xmlns:local="clr-namespace:Gelsineve_Panel.ViewModel;assembly=Gelsineve_Panel">

    <ContentPage.BindingContext>

        <local:KategoriTestPageModel x:Name="viewModel"/>

    </ContentPage.BindingContext>

    <ContentPage.Content>

      <sfTreeView:SfTreeView x:Name="treeView"

                               Indentation="15"

                               ExpanderWidth="40"

                               AutoExpandMode="AllNodesExpanded"

                               LoadOnDemandCommand="{Binding TreeViewOnDemandCommand}"

                               ItemsSource="{Binding KategoriDTOs}">

    <sfTreeView:SfTreeView.ItemTemplate>

        <DataTemplate>

            <ViewCell>

                <ViewCell.View>

                        <Grid Padding="5">

                            <Label

                                Text="{Binding KategoriAdi}"

                                />

                        </Grid>

                </ViewCell.View>

            </ViewCell>

        </DataTemplate>

    </sfTreeView:SfTreeView.ItemTemplate>

        </sfTreeView:SfTreeView>

    </ContentPage.Content>

</ContentPage>




ModelView Codes


    public class KategoriTestPageModel : BaseViewModel

    {

        public ICommand LoadDataCommand => new AsyncCommand(_ => LoadKategoriList());

        public ICommand TreeViewOnDemandCommand

        { get; set;}

        public KategoriTestPageModel()

        {

            TreeViewOnDemandCommand = new Command(ExecuteOnDemandLoading, CanExecuteOnDemandLoading);

            KategoriDTOs = new ObservableCollection<KategoriDTO>();

            LoadDataCommand.Execute(null);

        }

        private ObservableCollection<KategoriDTO> kategoriDTOs;

        public ObservableCollection<KategoriDTO> KategoriDTOs

        {

            get => kategoriDTOs;

            set => SetProperty(ref kategoriDTOs, value);

        }

private async Task LoadKategoriList()

        {

            IsBusy = true;

            KategoriDTOs.Clear();

            int sayfa = 1;

            int toplamSayfa = 1;

            do

            {

                var request = new ResServiceApiKategoriPerentIdData

                {

                    UserData = new ResServiceApiUser

                    {

                        User = Settings.DefaultSettings.SiteUserName,

                        Pass = Settings.DefaultSettings.SiteUserPassword

                    },

                    Gosterim = 50,

                    Sayfa = sayfa,

                    ParentID = 0

                };

                var result = await TryExecuteWithLoadingIndicatorsAsync(RestPoolService.KategoriApi.GetKategoriDTOListByPerentId(request));

                if (result.IsError || result.Value == null || result.Value.KategoriListe == null)

                {

                    IsBusy = false;

                    XSnackService.ShowMessage($"Hata {result.IsError}");

                }

                foreach (var item in result.Value.KategoriListe)

                {

                    KategoriDTOs.Add(item);

                }

                if (sayfa == 1)

                    toplamSayfa = result.Value.ToplamSayfa + 1;

                sayfa++;

            }

            while (toplamSayfa > sayfa);

            IsBusy = false;

        }

      private bool CanExecuteOnDemandLoading(object sender)

        {

            return true;

        }


        private void ExecuteOnDemandLoading(object obj)

        {

            var node = obj as TreeViewNode;


            if (node.ChildNodes.Count > 0)

            {

                node.IsExpanded = true;

                return;

            }


            node.ShowExpanderAnimation = true;

            KategoriDTO kategori = node.Content as KategoriDTO;

            Device.BeginInvokeOnMainThread(async () =>

            {

                var items = await LoadAltKategoriList(kategori.ID);

                node.PopulateChildNodes(items);

                if (items.Count() > 0)

                    node.IsExpanded = true;


                node.ShowExpanderAnimation = false;

            });

        }


        private async Task<List<KategoriDTO>> LoadAltKategoriList(int kategoriId)

        {

            IsBusy = true;

            var altKategori = new List<KategoriDTO>();

            int sayfa = 1;

            int toplamSayfa = 1;

            do

            {

                var request = new ResServiceApiKategoriPerentIdData

                {

                    UserData = new ResServiceApiUser

                    {

                        User = Settings.DefaultSettings.SiteUserName,

                        Pass = Settings.DefaultSettings.SiteUserPassword

                    },

                    Gosterim = 50,

                    Sayfa = sayfa,

                    ParentID = kategoriId

                };


                var result = await TryExecuteWithLoadingIndicatorsAsync(RestPoolService.KategoriApi.GetKategoriDTOListByPerentId(request));


                if (result.IsError || result.Value == null || result.Value.KategoriListe == null)

                {

                    IsBusy = false;

                    XSnackService.ShowMessage($"Hata {result.IsError}");

                }


                altKategori.AddRange(result.Value.KategoriListe);

                if (sayfa == 1)

                    toplamSayfa = result.Value.ToplamSayfa + 1;


                sayfa++;

            }

            while (toplamSayfa > sayfa);

            IsBusy = false;

            return altKategori;

        }

    }


Lakshmi Natarajan [Syncfusion]
Replied On December 30, 2019 10:15 AM UTC

Hi Hakan, 
  
Thank you for using Syncfusion products. 
  
We have analyzed the reported query from our end. Based on the codes provided, we have prepared a sample using Newton.json to fetch data from the online resources with LoadOnDemand and SfTreeView works fine as expected. 
  
Sample link: TreeView 
  
Please check the sample and let us know if this meets your requirements. If not, please modify the sample and revert us back with the following details, 
 
1.      Issue replication sample 
2.      Syncfusion and Xamarin updated version 

It will be helpful for us to check on it and provide you the solution at the earliest.
 

Regards,
Lakshmi Natarajan
 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon