I need this function to set manually for each item the ItemSize.
i thought something like that:
or this
i want to display a construction drawing after click on it.
Hi Steven ,
We would
like to let you know that , SfListView allows to set the size of each item by
SfListView.QueryItemSize event. Please refer the below code snippet adding
the QueryItemSize event
, where you can
specify the size of each item.
Code snippet:
|
listView.QueryItemSize += ListView_QueryItemSize;
private void ListView_QueryItemSize(object sender, Syncfusion.Maui.ListView.QueryItemSizeEventArgs e) { if (e.ItemIndex == 2) { e.ItemSize = 200; } else { e.ItemSize = 50; }
} |
Please refer the below documentation for QuerySizeItem event,
Also we would like to know that where you want to display the construction diagram after clicking on an item, which would be helpful for us to provide the solution as soon as possible.
Regards,
Suthi Yuvaraj.
Hey thanks for reply.
This function does nothing.
After procedure ItemSize reset automatically to 48 without to show me the size 200 for a while, it just dont change the size, which makes no sense because my itemsize is default 40 and if i remove the xaml code itemsize=40, then there also cannot be a default from 48.
Here my XAML
C#
Test "without" Debug VIDEO:
https://gyazo.com/19d05031f2b8e439da9996e94a7fcc22
Test "with" Debug VIDEO:
https://shiiikk.tixte.co/Test_with_Debug.mp4
please watch last video carefully to understand what is going on there, after itemsize set, it sets auto back to 48.
PS. i use the latest Version
20.2.48 (sfListView)
Visual Studio 17.4.0 Preview 1
Hi Steven,
Sorry for the inconvenience caused.
We need to set the e.Handled property to True to update specified size to the item. When this property is not set, the decided size will not be set to the item.
Please refer to our user guidance document and code snippets to use the event below,
|
private void listView_QueryItemSize(object sender, Syncfusion.Maui.ListView.QueryItemSizeEventArgs e) { if (e.ItemIndex == 2) { e.ItemSize = 200; } else { e.ItemSize = 60; }
e.Handled = true; } |
Also, based on the given details, if you want to update the ItemSize when selecting the item, then you can achieve it either of the following approaches.
Approach 1:
We suggest you bind the height for item in the ItemTemplate and use SfListView.AutoFitMode as DynamicHeight.
Please refer to our user guidance document regarding the same,
Step 1: Define property in the model class to set size.
|
public class BookInfo : INotifyPropertyChanged { private string bookName; private string bookDesc; private double itemHeight = 50;
public double ItemHeight { get { return itemHeight; } set { itemHeight = value; OnPropertyChanged("ItemHeight"); } }
... }
|
Step 2: Bind the property to the HeightRequest of the element in the ItemTemplate. Also set AutoFitMode as DynamicHeight.
|
<syncfusion:SfListView x:Name="KontrollList" ItemsSource="{Binding BookInfo}" AutoFitMode="DynamicHeight" SelectionChanged="listView_SelectionChanged">
<syncfusion:SfListView.ItemTemplate> <DataTemplate> <Grid Padding="10" RowDefinitions="*,*" HeightRequest="{Binding ItemHeight}"> <Label Text="{Binding BookName}" FontAttributes="Bold" TextColor="Teal" FontSize="17" /> <Label Grid.Row="1" Text="{Binding BookDescription}" TextColor="Teal" FontSize="15"/> </Grid> </DataTemplate> </syncfusion:SfListView.ItemTemplate> ... |
Step 3: In the SelectionChanged event, update the height for the items.
|
private void listView_SelectionChanged(object sender, Syncfusion.Maui.ListView.ItemSelectionChangedEventArgs e) { if (e.AddedItems.Count > 0) { foreach (var item in e.AddedItems) { (item as BookInfo).ItemHeight = 140; } }
if (e.RemovedItems.Count > 0) { foreach (var item in e.RemovedItems) { (item as BookInfo).ItemHeight = 50; } } } |
Approach 2: The SfListView allows you to customize the SelectionItem using the SelectedItemTemplate. You can achieve your requirement by defining the SelectedItemTemplate with specified size. This will update the selected item with the specified height defined in the SelectedItemTemplate.
|
<syncfusion:SfListView x:Name="KontrollList" ItemsSource="{Binding BookInfo}" AutoFitMode="DynamicHeight">
<syncfusion:SfListView.ItemTemplate> <DataTemplate> <Grid RowDefinitions="*,*" HeightRequest="70"> <Label Text="{Binding BookName}" FontAttributes="Bold" TextColor="Teal" /> <Label Grid.Row="1" Text="{Binding BookDescription}" TextColor="Teal" LineBreakMode="WordWrap"/> </Grid> </DataTemplate> </syncfusion:SfListView.ItemTemplate>
<syncfusion:SfListView.SelectedItemTemplate> <DataTemplate> <Grid RowDefinitions="*,*" HeightRequest="140"> <Label Text="{Binding BookName}" FontAttributes="Bold" TextColor="Teal" /> <Label Grid.Row="1" Text="{Binding BookDescription}" TextColor="Teal" /> </Grid> </DataTemplate> </syncfusion:SfListView.SelectedItemTemplate> </syncfusion:SfListView>
|
Please refer to our user guidance document to customize the SelectedItemTemplate,
UG link: https://help.syncfusion.com/maui/listview/selection#selected-item-customization
We have attached the sample for your reference. Please let us know if you need further assistance.
Regards,
Lakshmi Natarajan