Data sorting with columns in Unity
Hi,
I'm trying to make table with data that can be filtered and sorted by some values. I ended up with ListView and GridView as View for that List. To allow user to sort rows by values in columns I added ColumHeader with call to appropriate method in CodeBehind. It's works pretty good in Visual Studio as XAML project. XAML code below.
But when I tried to run it in Unity I met same complications.
1.
Code above subscribe event but don't call assigned method on actually click. Is it my miss understand of this system or bug?
2. I worked around above with:
but then in my sorting method after cast sender to GridViewColumnHeader the Column property is null. I need this for:
Are those knows issues? Is there any better way to do that?
TIA
I'm trying to make table with data that can be filtered and sorted by some values. I ended up with ListView and GridView as View for that List. To allow user to sort rows by values in columns I added ColumHeader with call to appropriate method in CodeBehind. It's works pretty good in Visual Studio as XAML project. XAML code below.
Code: Select all
<ListView Grid.ColumnSpan="5" Grid.Row="2" ItemsSource="{Binding FilteredApartament}">
<ListView.View>
<GridView AllowsColumnReorder="False">
<GridViewColumn DisplayMemberBinding="{Binding Path=ID}" Width="100">
<GridViewColumnHeader Content="ID" Click="Sort" />
</GridViewColumn>
<GridViewColumn DisplayMemberBinding="{Binding Path=Floor}" Width="100">
<GridViewColumnHeader Content="Floor" Click="Sort" />
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
1.
Code: Select all
protected override bool ConnectEvent(object source, string eventName, string handlerName)
{
if (eventName == "Click" && handlerName == "Sort")
{
((GridViewColumnHeader)source).Click += this.Sort;
return true;
}
return false;
}
2. I worked around above with:
Code: Select all
protected override bool ConnectEvent(object source, string eventName, string handlerName)
{
if (eventName == "Click" && handlerName == "Sort")
{
var g = (GridViewColumnHeader)source;
g.MouseDown += this.Sort;
g.Click += this.Sort;
return true;
}
return false;
}
Code: Select all
columnHeaderClicked.Column.HeaderTemplate = direction == SortState.Ascending ?
Resources["HeaderTemplateArrowUp"] as DataTemplate :
Resources["HeaderTemplateArrowDown"] as DataTemplate;
TIA
-
sfernandez
Site Admin
- Posts: 2983
- Joined:
Re: Data sorting with columns in Unity
Hi,
I reviewed the code and found we have a bug there. Because we are always creating a GridViewColumnHeader instance to use as Content what is defined in GridViewColumn.Header. So what is happening is that Click is raised for that internally generated object instead of the one defined in xaml.
Could you please report this in our bugtracker so we can keep track of the problem, thanks.
Meanwhile the solution will be quite tricky, because you would need to search (on the Loaded event) for the GridViewHeaderRowPresenter inside the ListView template, and get the generated GridViewColumnHeader by iterating its visual children. Then you can attach the Click handler to the correct headers. Let me know if you need help with that.
I reviewed the code and found we have a bug there. Because we are always creating a GridViewColumnHeader instance to use as Content what is defined in GridViewColumn.Header. So what is happening is that Click is raised for that internally generated object instead of the one defined in xaml.
Could you please report this in our bugtracker so we can keep track of the problem, thanks.
Meanwhile the solution will be quite tricky, because you would need to search (on the Loaded event) for the GridViewHeaderRowPresenter inside the ListView template, and get the generated GridViewColumnHeader by iterating its visual children. Then you can attach the Click handler to the correct headers. Let me know if you need help with that.
Re: Data sorting with columns in Unity
Hi i can also confirm this bug inside C# (No Unity)
Click action will bind but not be called.
MouseLeftButtonDown does in fact get called, but Column property is empty.
Click action will bind but not be called.
MouseLeftButtonDown does in fact get called, but Column property is empty.
-
sfernandez
Site Admin
- Posts: 2983
- Joined:
Re: Data sorting with columns in Unity
I created a ticket to follow the resolution of this bug: https://www.noesisengine.com/bugs/view.php?id=1499
Who is online
Users browsing this forum: Ahrefs [Bot], Google [Bot] and 37 guests