Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GroupStyleSelector for a ListView

I am trying to make a custom groupstyle sector for my ListView as per other questions I've seen here on stack overflow.

public class TestGroupStyleSelector : GroupStyleSelector
{
    protected override GroupStyle SelectGroupStyleCore(object item, uint level)
    {
            return (GroupStyle)App.Current.Resources["grpStyle"];
    }
}

<ListView GroupStyleSelector="{StaticResource grpStyleSelector}">

I have two errors with this:

Error 1 'TestGroupStyleSelector': cannot derive from sealed type 'System.Windows.Controls.GroupStyleSelector'

Error 2 An object of the type "TestGroupStyleSelector" cannot be applied to a property that expects the type "System.Windows.Controls.GroupStyleSelector".

I have declared the class as other questions on here have shown, I am pretty lost at this point as to how to create a groupstyleselector for my listview, any ideas?

like image 500
nextint Avatar asked Oct 24 '25 19:10

nextint


1 Answers

In WPF, using

<ListView GroupStyleSelector="{StaticResource grpStyleSelector}" />

and inheriting your selector from GroupStyleSelector will result in a 'cannot derive from sealed type 'System.Windows.Controls.GroupStyleSelector' exception.

Instead, use

<ListView>
   <ListView.GroupStyle>
     <GroupStyle ContainerStyleSelector="{StaticResource grpStyleSelector}"  />
   </ListView.GroupStyle>
</ListView>

and inherit your selector from StyleSelector

like image 133
Nick Avatar answered Oct 26 '25 09:10

Nick