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

Not able to show sfTreeview

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;

        }

    }


1 Reply

LN Lakshmi Natarajan Syncfusion Team 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
 


Loader.
Live Chat Icon For mobile
Up arrow icon