Data sorting with columns in Unity
Posted: 31 Jul 2018, 16:30
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