The GridView has a nasty feature I don't quite understand. It concerns the visual studio intellisense connection (XAML) of the collection in the ItemsSource and the DataMemberBinding on the column when using AutoGenerateColumns=False.
The problem is that if you Qualify the attached property type, so it reacts to property name changes and can be naviagted to using F12, the column cannot be filtered or grouped anymore.
Qualify looks like this:
DataMemberBinding="{Binding Path=(model: xxx)"
The unqualified looks like this:
DataMemberBinding="{Binding Path= xxx" this gives a blue line underneath
The DataContext of the column obviously isn't the DataContext of the Window.
The values in the cells are correct.
The message I get from visual studio is 'Cannot resolve property 'xxx' in data context of type 'object'.
In DataTemplates a similar thing happens, but you can set the DataType or I use d:DataContext={xxx}
I there a way to do this?
11 Answers, 1 is accepted
Hello Max,
Can you please share what version of Visual Studio you are using? I have tested with Microsoft Visual Studio Professional 2019 16.4.3 and the following binding works:
<telerik:GridViewDataColumn Header="Established" UniqueName="Established" DataMemberBinding="{Binding Path=(my:Club.Established)}"/>
Regards,
Yoan
Progress Telerik
I'm using 16.4.5, the latest at this time.
The qualifying works just fine, but the filtering and grouping is locked.
Hello Max,
Indeed, you are right, please excuse me for misleading you.
This could be easily overcome by setting the SortMemberPath/FilterMemberPath = "Established" property of the column.
Regards,
Yoan
Progress Telerik
Thanks for your reply Yoan,
I think I'm one step closer but not there yet.
What I understand now is this (see code sniplet)
<
telerik:GridViewDataColumn
DataMemberBinding
=
"{Binding Path=(model:ExchangeArticleList.ListId)}"
FilterMemberPath
=
"Established"
SortMemberPath
=
"Established"
UniqueName
=
"ListId"
>
This still does not show the filter of the column. But when I change it to..
FilterMemberPath="ListId"
it works fine. However the property ListId is not linked live. So when I rename the property from ListId to ListIds, the filtering is broken again. Is this what you mean?
Hello Max,
Actually, the "Established" property is a property from my test view model. You can set the SortMemberPath property of a column to specify the name of the property the data in the column will be sorted by. The same is valid for the FilterMemberPath property. So, yes, you need to set it to be the property to which you bind the column.
I hope this helps.
Regards,
Yoan
Progress Telerik
I did some more research and been able to use fully type qualification for the FilterMemberPath and SortMemberPath as well, using a simple MarkupExtension.
In this way you don't have any problems when you rename your properties as it does not require a string as input.
public class NameOfExtension : MarkupExtension
{
private readonly PropertyPath _propertyPath;
public NameOfExtension(Binding binding)
{
_propertyPath = binding.Path;
}
public override object ProvideValue(IServiceProvider serviceProvider)
{
return ((PropertyInfo)_propertyPath.PathParameters.First()).Name;
}
}
It is used in XAML as follows:
<
telerik:GridViewDataColumn
DataMemberBinding
=
"{Binding Path=(model:TrackerArticleCategory.DisplayName)}"
FilterMemberPath
=
"{model:NameOf {Binding Path=(model:TrackerArticleCategory.DisplayName)}}"
Header
=
"Article Id"
SortMemberPath
=
"{model:NameOf {Binding Path=(model:TrackerArticleCategory.DisplayName)}}"
/>
I settled on an extension class of the GridViewDataColumn. This ensures I dont have to qualify alll the properties seperately and negating the chance of typos.
public class TypeQualifiedColumn: GridViewDataColumn
{
protected override void OnDataMemberBindingChanged()
{
base.OnDataMemberBindingChanged();
var propertyPath= DataMemberBinding.Path;
var name = ((PropertyInfo)propertyPath.PathParameters.First()).Name;
SortMemberPath = name;
FilterMemberPath = name;
}
}
Hello Max,
Thank you for sharing your solution with the community. As a gratitude for this, I have updated your Telerik points.
Regards,
Yoan
Progress Telerik
Our thoughts here at Progress are with those affected by the outbreak.