tesrt
Topic Author
Posts: 7
Joined: 08 Mar 2020, 15:17

Connect GridViewColumnHeader.Click event from ListView

23 Apr 2020, 12:20

I have a ListView and I want to connect the event GridViewColumnHeader.Click to the function PersonListView_Click
<ListView ItemsSource="{Binding Person}" GridViewColumnHeader.Click="PersonListView_Click">
            <ListView.View>
                <GridView>
                    <GridViewColumn DisplayMemberBinding="{Binding Name}" />
        protected override bool ConnectEvent(object source, string eventName, string handlerName)
        {
            if (eventName == "Click" && handlerName == "PersonListView_Click")
            {
                Debug.Log(source);
                ViewBase v = ((ListView)source).View;
                
                // += this.PersonListView_Click;
                return true;
            }
            return false;
        }
How can I setup the ConnectEvent in order to recieve the click event when I click on the header/GridViewColumn of my ListView ?

Tags:
 
User avatar
sfernandez
Site Admin
Posts: 1973
Joined: 22 Dec 2011, 19:20

Re: Connect GridViewColumnHeader.Click event from ListView

23 Apr 2020, 13:26

In this case you should use the AddHandler method because ListView does not define the Click event and you are using it as an attached routed event:
        protected override bool ConnectEvent(object source, string eventName, string handlerName)
        {
            if (eventName == "Click" && handlerName == "PersonListView_Click")
            {
                ((ListView)source).AddHandler(GridViewColumnHeader.ClickEvent, new RoutedEventHandler(this.PersonListView_Click));
                return true;
            }
            return false;
        }
 
tesrt
Topic Author
Posts: 7
Joined: 08 Mar 2020, 15:17

Re: Connect GridViewColumnHeader.Click event from ListView

23 Apr 2020, 14:10

Thank you for your help!

Who is online

Users browsing this forum: No registered users and 8 guests