|
public class SfListViewExt : SfListView
{
VisualContainer container;
double extent;
public SfListViewExt()
{
container = this.GetVisualContainer();
container.PropertyChanged += Container_PropertyChanged;
}
private void Container_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
Device.BeginInvokeOnMainThread(async () =>
{
extent = (double)container.GetType().GetRuntimeProperties().FirstOrDefault(container => container.Name == "TotalExtent").GetValue(container);
if (e.PropertyName == "Height")
{
(this.BindingContext as ItemInfo).Height = extent;
}
});
}
} |
|
public class ItemInfo : INotifyPropertyChanged
{
private bool _isExpanded;
private double _height=1000;
public double Height
{
get => _height;
set
{
_height = value;
OnPropertyChanged("Height");
}
}
public bool IsExpanded
{
get => _isExpanded;
set
{
_isExpanded = value;
OnPropertyChanged("IsExpanded");
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string Property)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(Property));
}
} |
|
Hi Tayyip,Thank you for your patience.We have checked the reported query “Hide empty space in SfListView” from our end. We would like to let you know that you can achieve your requirement by extending ListView used as Expander content. Add ListView inside Grid layout in Expander Content. You can get the TotalExtent (height) of the ListView using Container PropertyChanged event and assign the value to a model property, bind the model property to ListView HeightRequest and Parent Grid HeightRequest. Please refer the following code snippets for more reference,C#: Extending ListView and getting TotalExtent using Container PropertyChanged event
public class SfListViewExt : SfListView{VisualContainer container;double extent;public SfListViewExt(){container = this.GetVisualContainer();container.PropertyChanged += Container_PropertyChanged;}private void Container_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e){Device.BeginInvokeOnMainThread(async () =>{extent = (double)container.GetType().GetRuntimeProperties().FirstOrDefault(container => container.Name == "TotalExtent").GetValue(container);if (e.PropertyName == "Height"){(this.BindingContext as ItemInfo).Height = extent;}});}}C#: Defining Height and IsExpanded property
public class ItemInfo : INotifyPropertyChanged{private bool _isExpanded;private double _height=1000;public double Height{get => _height;set{_height = value;OnPropertyChanged("Height");}}public bool IsExpanded{get => _isExpanded;set{_isExpanded = value;OnPropertyChanged("IsExpanded");}}public event PropertyChangedEventHandler PropertyChanged;private void OnPropertyChanged(string Property){PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(Property));}}Xaml: Binding HeightRequest to ListView and Parent Grid
<sflistview:SfListView x:Name="listView" AutoFitMode="DynamicHeight" SelectionMode="Single" IsScrollBarVisible="False" ItemSpacing="0"><sflistview:SfListView.ItemTemplate><DataTemplate><sfExpander:SfExpander x:Name="sfExpander" Expanded="SfExpander_Expanded" IsExpanded="{Binding IsExpanded}" IconColor="Black" HeaderBackgroundColor="#B8F272" DynamicSizeMode="Content"><sfExpander:SfExpander.Header><Grid x:Name="grid" BackgroundColor="#009E91" CompressedLayout.IsHeadless="true">…</Grid></sfExpander:SfExpander.Header><sfExpander:SfExpander.Content><Grid HeightRequest="{Binding Height}"><local:SfListViewExt ItemsSource="{Binding Services}" AutoFitMode="DynamicHeight" FocusBorderColor="#B8F272" SelectionBackgroundColor="#B8F272" ItemTapped="SfListView_ItemTapped" HeightRequest="{Binding Height}"><local:SfListViewExt.ItemTemplate><DataTemplate><Grid BackgroundColor="#54D0C1" Padding="10">…</Grid></DataTemplate></local:SfListViewExt.ItemTemplate></local:SfListViewExt></Grid></sfExpander:SfExpander.Content></sfExpander:SfExpander></DataTemplate></sflistview:SfListView.ItemTemplate></sflistview:SfListView>Note: ListView uses Recycle Strategy, where the items are loaded only coming into view. So, you have to bind Expander IsExpanded property to avoid expanding other items.Please refer our Online UG document for more reference,UG Link: https://help.syncfusion.com/xamarin/listview/working-with-sflistview#working-with-nested-listviewPlease let us know if you need further assistance.Regards,Chandrasekar Sampathkumar
|
<sflistview:SfListView x:Name="listView" ListViewCachingStrategy="CreateNewTemplate" ItemsSource="{Binding Info}" AutoFitMode="DynamicHeight" SelectionMode="Single" IsScrollBarVisible="False" ItemSpacing="0">
<sflistview:SfListView.ItemTemplate>
<DataTemplate>
<sfExpander:SfExpander x:Name="{Binding ExpanderID}" IsExpanded="{Binding IsExpanded}" IconColor="Black" HeaderBackgroundColor="#B8F272" DynamicSizeMode="Content">
<sfExpander:SfExpander.Header>
<Grid x:Name="grid" BackgroundColor="#009E91" CompressedLayout.IsHeadless="true">
...
</Grid>
</sfExpander:SfExpander.Header>
<sfExpander:SfExpander.Content>
<Grid>
<local:SfListViewExt ItemsSource="{Binding Varieties}" AutoFitMode="DynamicHeight" FocusBorderColor="#B8F272" SelectionBackgroundColor="#B8F272" >
<local:SfListViewExt.ItemTemplate>
<DataTemplate>
...
</DataTemplate>
</local:SfListViewExt.ItemTemplate>
</local:SfListViewExt>
</Grid>
</sfExpander:SfExpander.Content>
</sfExpander:SfExpander>
</DataTemplate>
</sflistview:SfListView.ItemTemplate>
</sflistview:SfListView> |
Hi Tayyip,Sorry for the delay caused.We would like to let you know that the reported scenario occurs due to ListView’s reusing strategy. You can overcome the reported scenario by setting ListViewCachingStrategy as CreateNewTemplate to outer ListView. Please refer the following code snippets for more reference,Xaml: Adding ListViewCachingStrategy property to outer ListView
<sflistview:SfListView x:Name="listView" ListViewCachingStrategy="CreateNewTemplate" ItemsSource="{Binding Info}" AutoFitMode="DynamicHeight" SelectionMode="Single" IsScrollBarVisible="False" ItemSpacing="0"><sflistview:SfListView.ItemTemplate><DataTemplate><sfExpander:SfExpander x:Name="{Binding ExpanderID}" IsExpanded="{Binding IsExpanded}" IconColor="Black" HeaderBackgroundColor="#B8F272" DynamicSizeMode="Content"><sfExpander:SfExpander.Header><Grid x:Name="grid" BackgroundColor="#009E91" CompressedLayout.IsHeadless="true">...</Grid></sfExpander:SfExpander.Header><sfExpander:SfExpander.Content><Grid><local:SfListViewExt ItemsSource="{Binding Varieties}" AutoFitMode="DynamicHeight" FocusBorderColor="#B8F272" SelectionBackgroundColor="#B8F272" ><local:SfListViewExt.ItemTemplate><DataTemplate>...</DataTemplate></local:SfListViewExt.ItemTemplate></local:SfListViewExt></Grid></sfExpander:SfExpander.Content></sfExpander:SfExpander></DataTemplate></sflistview:SfListView.ItemTemplate></sflistview:SfListView>Please let us know if you need further assistance.Regards,Chandrasekar Sampathkumar