I'm building a way to generate columns based on an IEnumerable inside a ViewModel bound to a single row.
When creating a cell element, the DataContext of that element is set to something based on a property path.
Consider the following example:
The DataMemberBindingPath contains something like Lines[0] or Lines[1]. This works fine since the WPF data binding engine can handle this. When I try to define the SortMemberPath containing an Indexer, nothing happens and the expression does not seem to be parsed.
Looking at the GridViewColumn source code, there is a method of interest:
However the method is Internal and I cannot override this to allow working with indexers.
Is there any workaround available to override the sort behavior for a custom column?
When creating a cell element, the DataContext of that element is set to something based on a property path.
Consider the following example:
class Order {
public List<
OrderLine
> Lines { get; }
}
class OrderLine {
public int Index { get; }
public string Data { get; }
}
- A GridViewRow would be bound to an Order object.
- For each line in this example a column will be created.
To achieve this, I created a custom column:
public override FrameworkElement CreateCellElement(GridViewCell cell, object dataItem)
{
// more code to create item etc.
item.SetBinding(FrameworkElement.DataContextProperty,
new Binding(DataMemberBindingPath) { Source = dataItem });
}
The DataMemberBindingPath contains something like Lines[0] or Lines[1]. This works fine since the WPF data binding engine can handle this. When I try to define the SortMemberPath containing an Indexer, nothing happens and the expression does not seem to be parsed.
Looking at the GridViewColumn source code, there is a method of interest:
internal virtual Expression CreateSortKeyExpression(ParameterExpression parameterExpression, ExpressionBuilderOptions options)
{
var builder = CreateBuilder(parameterExpression, this.EffectiveSortMemberType, this.EffectiveSortMemberPath, options);
return builder.CreateMemberAccessExpression();
}
However the method is Internal and I cannot override this to allow working with indexers.
Is there any workaround available to override the sort behavior for a custom column?