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

Not able to show sfTreeview

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

1 Reply

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


Loader.
Live Chat Icon For mobile
Up arrow icon