wyvern010
Topic Author
Posts: 24
Joined: 18 Apr 2019, 13:41

selectable element after last character in ListviewHeader

18 Jun 2019, 22:47

As the topic says:
Image
<UserControl x:Class="WpfApp1.SSC.PersonsListView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:WpfApp1.SSC"
             mc:Ignorable="d" 
             d:DesignHeight="450" d:DesignWidth="800">
    <ListView Grid.Row="2" ItemsSource="{Binding cbPersons}">
        <ListView.View>
            <GridView>
                <GridViewColumn>
                    <GridViewColumn.Header>
                        <GridViewColumnHeader Tag="Firstname" MouseLeftButtonDown="GridViewColumnHeader_MouseLeftButtonDown">First name</GridViewColumnHeader>
                    </GridViewColumn.Header>
                    <GridViewColumn.CellTemplate>
                        <DataTemplate >
                            <TextBlock Text="{Binding Firstname}" Style="{StaticResource TextColor}" ></TextBlock>
                        </DataTemplate>
                    </GridViewColumn.CellTemplate>
                </GridViewColumn>
                <GridViewColumn>
                    <GridViewColumn.Header>
                        <GridViewColumnHeader Tag="Lastname" MouseLeftButtonDown="GridViewColumnHeader_MouseLeftButtonDown">Last name</GridViewColumnHeader>
                    </GridViewColumn.Header>
                    <GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Lastname}" Style="{StaticResource TextColor}" ></TextBlock>
                        </DataTemplate>
                    </GridViewColumn.CellTemplate>
                </GridViewColumn>
            </GridView>
        </ListView.View>
    </ListView>
</UserControl>

i dont know what is, but i think its ugly.
Last edited by wyvern010 on 19 Jun 2019, 11:37, edited 1 time in total.

Tags:
 
User avatar
digimbyte
Posts: 47
Joined: 14 Nov 2017, 21:42

Re: selectable element after last character in ListviewHeader

19 Jun 2019, 00:22

Show code please, a tiny picture doesn't explain anything
 
wyvern010
Topic Author
Posts: 24
Joined: 18 Apr 2019, 13:41

Re: selectable element after last character in ListviewHeader

19 Jun 2019, 11:44

Show code please, a tiny picture doesn't explain anything
Updated.
 
User avatar
sfernandez
Site Admin
Posts: 2109
Joined: 22 Dec 2011, 19:20

Re: selectable element after last character in ListviewHeader

20 Jun 2019, 13:10

It is a bug in the GridViewHeaderRowPresenter, because it is wrapping the GridViewColumnHeader you specified with another one. I created a report in our bugtracker for this: https://www.noesisengine.com/bugs/view.php?id=1502

While we fix it you can workaround this issue by specifying directly the header text in the GridViewColumn:
<GridViewColumn Header="First name"/>
And you can handle the header clicks in the ListView control, checking if the sender of the event is a GridViewColumnHeader:
<ListView ... ButtonBase.Click="GridViewColumnHeader_Click">
private void GridViewColumnHeader_Click(object sender, MouseButtonEventArgs e)
{
  if (sender is GridViewColumnHeader) { ... }
}
Please confirm this is working for you.
 
wyvern010
Topic Author
Posts: 24
Joined: 18 Apr 2019, 13:41

Re: selectable element after last character in ListviewHeader

20 Jun 2019, 19:34

Did exactly as you said:
<GridViewColumn Header="First name">
 <ListView Grid.Row="2" ItemsSource="{Binding cbPersons}" MouseDoubleClick="ListView_MouseDoubleClick" ButtonBase.Click="GridViewColumnHeader_Click" SelectedItem="{Binding SelectedPerson}">
 
  private void GridViewColumnHeader_Click(object sender, RoutedEventArgs e)
        {
    (breakpoint not hit)        GridViewColumnHeader column = (sender as GridViewColumnHeader);
        }
            

The GridViewColumnHeader_Click get assigned, but not called.
I've put a breakpoint on the first line into the function, which didn't hit.
 
User avatar
sfernandez
Site Admin
Posts: 2109
Joined: 22 Dec 2011, 19:20

Re: selectable element after last character in ListviewHeader

21 Jun 2019, 17:46

I suppose you have overriden the ConnectEvent method in the code-behind class:
    protected override bool ConnectEvent(object source, string eventName, string handlerName)
    {
        if (eventName == "Click" && handlerName == "GridViewColumnHeader_Click")
        {
            ((UIElement)source).AddHandler(ButtonBase.ClickEvent, new RoutedEventHandler(GridViewColumnHeader_Click));
            return true;
        }
        //...
        return false;
    }
Without that piece of code event handlers won't be registered so will never be called.
 
wyvern010
Topic Author
Posts: 24
Joined: 18 Apr 2019, 13:41

Re: selectable element after last character in ListviewHeader

22 Jun 2019, 13:21

I did hookup it wrong, now the GridViewColumnHeader_Click(object sender, RoutedEventArgs e) gets called, but the sender is always ListView.

all code in
 if (sender is GridViewColumnHeader) { .. }
never gets executed.

Edit:
 if (sender is GridViewColumnHeader) { .. }

must be
 if (e.Source is GridViewColumnHeader) { .. }

Now works as expected!

Side effect is that i can't use the ColumnHeader.Tag to pass data to the Sorting function.
 
User avatar
sfernandez
Site Admin
Posts: 2109
Joined: 22 Dec 2011, 19:20

Re: selectable element after last character in ListviewHeader

25 Jun 2019, 10:11

You're right, it should be e.Source, the object who initially fired the event.
To help with the sorting, can't you use the Column info of the GridViewColumnHeader?

Who is online

Users browsing this forum: jsantos, Kate_ferris and 1 guest