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