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:

150232 Dec 27,2019 05:56 AM UTC Dec 30,2019 10:16 AM UTC Xamarin.Forms 1
loading
Tags: SfTreeView
Hakan COSKUN
Asked On December 27, 2019 05:56 AM UTC

Hi;
I want to use sfTreeview, but there is no image on the page. 
Despite my long-term research, I couldn't solve the problem. Waiting for your help.

----------------------------
<?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}"
                               ChildPropertyName="AltKategori"
                             >
    <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>


----------------------------


public class KategoriTestPageModel : BaseViewModel
    {
        private ObservableCollection<KategoriDTO> kategoriDTOs;
        public ObservableCollection<KategoriDTO> KategoriDTOs
        {
            get => kategoriDTOs;
            set => SetProperty(ref kategoriDTOs, value);
        }

        //private ObservableCollection<KategoriDTO> kategoriDTOs;
        //public ObservableCollection<KategoriDTO> KategoriDTOs
        //{
        //    get { return kategoriDTOs; }
        //    set { kategoriDTOs = value; }
        //}


        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 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}");
                }

                //KategoriDTOs.AddRange(result.Value.KategoriListe);
                foreach (var item in result.Value.KategoriListe)
                {
                    KategoriDTOs.Add(item);
                }

                if (sayfa == 1)
                    toplamSayfa = result.Value.ToplamSayfa + 1;

                sayfa++;
            }
            while (toplamSayfa > sayfa);

            //foreach (var item in KategoriDTOs)
            //{
            //    var xxx = await LoadAltKategoriList(item.KategoriID);
            //    if (xxx != null && xxx.Count > 0)
            //    {
            //        if (item.AltKategori == null)
            //            item.AltKategori = new List<KategoriDTO>();
            //        item.AltKategori.AddRange(xxx);
            //    }
            //}

            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:16 AM UTC

Hi Hakan, 
 
Thank you for using Syncfusion products. 
 
We have updated the response for the reported query in another forum for same query. Please find the response in the respected forum (150222) for further updates. 
 
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