selectable element after last character in ListviewHeader
As the topic says:
i dont know what is, but i think its ugly.
Code: Select all
<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>
Last edited by wyvern010 on 19 Jun 2019, 11:37, edited 1 time in total.
Re: selectable element after last character in ListviewHeader
Show code please, a tiny picture doesn't explain anything
Re: selectable element after last character in ListviewHeader
Updated.Show code please, a tiny picture doesn't explain anything
-
sfernandez
Site Admin
- Posts: 2984
- Joined:
Re: selectable element after last character in ListviewHeader
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:
And you can handle the header clicks in the ListView control, checking if the sender of the event is a GridViewColumnHeader:
Please confirm this is working for you.
While we fix it you can workaround this issue by specifying directly the header text in the GridViewColumn:
Code: Select all
<GridViewColumn Header="First name"/>
Code: Select all
<ListView ... ButtonBase.Click="GridViewColumnHeader_Click">
Code: Select all
private void GridViewColumnHeader_Click(object sender, MouseButtonEventArgs e)
{
if (sender is GridViewColumnHeader) { ... }
}
Re: selectable element after last character in ListviewHeader
Did exactly as you said:
The GridViewColumnHeader_Click get assigned, but not called.
I've put a breakpoint on the first line into the function, which didn't hit.
Code: Select all
<GridViewColumn Header="First name">
Code: Select all
<ListView Grid.Row="2" ItemsSource="{Binding cbPersons}" MouseDoubleClick="ListView_MouseDoubleClick" ButtonBase.Click="GridViewColumnHeader_Click" SelectedItem="{Binding SelectedPerson}">
Code: Select all
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.
-
sfernandez
Site Admin
- Posts: 2984
- Joined:
Re: selectable element after last character in ListviewHeader
I suppose you have overriden the ConnectEvent method in the code-behind class:
Without that piece of code event handlers won't be registered so will never be called.
Code: Select all
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;
}
Re: selectable element after last character in ListviewHeader
I did hookup it wrong, now the GridViewColumnHeader_Click(object sender, RoutedEventArgs e) gets called, but the sender is always ListView.
all code in never gets executed.
Edit:
must be
Now works as expected!
Side effect is that i can't use the ColumnHeader.Tag to pass data to the Sorting function.
all code in
Code: Select all
if (sender is GridViewColumnHeader) { .. }
Edit:
Code: Select all
if (sender is GridViewColumnHeader) { .. }
must be
Code: Select all
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.
-
sfernandez
Site Admin
- Posts: 2984
- Joined:
Re: selectable element after last character in ListviewHeader
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?
To help with the sorting, can't you use the Column info of the GridViewColumnHeader?
Who is online
Users browsing this forum: Bing [Bot], Google [Bot] and 76 guests