Grouped CollectionView visible

1 Answer 152 Views
CollectionView
Rodrigo
Top achievements
Rank 1
Rodrigo asked on 11 Jul 2024, 08:04 PM

Hi!

I migrated from Listview to Collectionview and I have 2 problems.
Can you help me?
1- Is it possible to hide the group indicator?
2- This blank space appears at the end of the layout. In the Listview everything is ok, but in the CollectionView I couldn't identify it. Do you know what it could be?

1 Answer, 1 is accepted

Sort by
0
Yana
Telerik team
answered on 12 Jul 2024, 09:36 AM

Hi Rodrigo,

Both issues can be resolved by creating a GroupViewStyle for the CollectionView:

1 - the group indicator is added into the GroupView ControlTemplate, so you'd need to override it to remove it.

2 - this is the padding set inside the GroupViewStyle.

Here is a sample GroupViewStyle you can use:

<ControlTemplate x:Key="RadCollectionViewGroupItem_ControlTemplate">
        <Grid ColumnDefinitions="*"
                Padding="{TemplateBinding ActualPadding}">
        <ContentPresenter />
    </Grid>
</ControlTemplate>

<Style x:Key="GroupHeaderStyle" TargetType="telerik:RadCollectionViewGroupView">
    <Setter Property="ControlTemplate" Value="{StaticResource RadCollectionViewGroupItem_ControlTemplate}" />
    <Setter Property="Padding" Value="0" />
</Style>

 

Just apply the GroupHeaderStyle resource to the CollectionView's GroupViewStyle:

<telerik:RadCollectionView ItemsSource="{Binding Locations}"
                        DisplayMemberPath="City"
                        GroupViewStyle="{StaticResource GroupHeaderStyle}">
    <telerik:RadCollectionView.BindingContext>
        <local:ViewModel />
    </telerik:RadCollectionView.BindingContext>
    <telerik:RadCollectionView.GroupDescriptors>
        <telerik:PropertyGroupDescriptor PropertyName="Country" />
    </telerik:RadCollectionView.GroupDescriptors>
</telerik:RadCollectionView>

Give it a try and let me know if you have any additional questions on this.

Regards,
Yana
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Rodrigo
Top achievements
Rank 1
commented on 12 Jul 2024, 11:16 AM

Perfect! Thanks.
If I want it to always be expanded when someone clicks on the grouping, what should I do?

Regards,

Rodrigo.

Lance | Senior Manager Technical Support
Telerik team
commented on 12 Jul 2024, 05:21 PM | edited

Hi Rodrigo,

If I understand you correctly, you don't want a specific group to be collapsed if it is expanded and the user taps it?  There isn't a setting right now where you can define an exact group to not be collapsible.

However I have an idea that you can try that achieves the same end result.

When a group is tapped, it will trigger the GroupTapped event. Inside this event you can get a reference to the group's context;  see if the IsExpanded=false and the group's name. If all conditions match, then programmatically re-expand it.

Here's an example to explain better:

private async void RadCollectionView_OnGroupTapped(object sender, RadTappedEventArgs<GroupContext> e)
{
    // Get the references we need
    var collectionView = sender as RadCollectionView;
    var dataView = collectionView.GetDataView();

    // If the group is currently expanded and the group's title is "Belgium"
    if (!e.Data.IsExpanded && e.Data.Key.ToString() == "Belgium")
    {
        // Find the matching IDataGroup
        var matchingGroup = dataView.GetGroups().FirstOrDefault(g => g.Key == e.Data.Key);

        // You need a very short delay to allow the previous change's animation
        await Task.Delay(20);

        // Re-expand it
        dataView.ExpandGroup(matchingGroup);
    }
}

While this does have a very quick collapse/expand animation, it will force that group to stay open and achieves the ultimate goal.

Outside of this, we would need to build in an GroupTapping pre-trigger event that allows you to call some sort of e.Cancel() method to cancel the operation. I will mention this desire to the dev team to consider for future planning.

[Edit] Fixed misspelling and grammar to better clarify the suggestion.

Rodrigo
Top achievements
Rank 1
commented on 12 Jul 2024, 06:39 PM

Hi Lance!

Thanks for help!

Regards,

Rodrigo.

Lance | Senior Manager Technical Support
Telerik team
commented on 12 Jul 2024, 08:34 PM

Hi Rodrigo, I spoke with the devs and indeed my recommendation is the only suitable path right now. I did open this Feature Request on your behalf for them to consider adding something more official in time => [CollectionView] Add Cancellation support for group expand/collapse.

Tags
CollectionView
Asked by
Rodrigo
Top achievements
Rank 1
Answers by
Yana
Telerik team
Share this question
or