This is a migrated thread and some comments may be shown as answers.

Qualifying DataMemberBinding

11 Answers 423 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Max
Top achievements
Rank 1
Veteran
Iron
Max asked on 24 Feb 2020, 02:22 PM

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

Sort by
0
Yoan
Telerik team
answered on 27 Feb 2020, 11:35 AM

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

Version 16.4.3
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Max
Top achievements
Rank 1
Veteran
Iron
answered on 02 Mar 2020, 07:24 PM

I'm using 16.4.5, the latest at this time.

 

The qualifying works just fine, but the filtering and grouping is locked.

0
Accepted
Yoan
Telerik team
answered on 05 Mar 2020, 02:21 PM

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

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Max
Top achievements
Rank 1
Veteran
Iron
answered on 05 Mar 2020, 03:36 PM

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">

0
Max
Top achievements
Rank 1
Veteran
Iron
answered on 05 Mar 2020, 03:38 PM

 

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?

0
Yoan
Telerik team
answered on 06 Mar 2020, 08:29 AM

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

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Max
Top achievements
Rank 1
Veteran
Iron
answered on 09 Mar 2020, 11:50 AM
Thank you so much Yoan.
0
Max
Top achievements
Rank 1
Veteran
Iron
answered on 13 May 2020, 11:38 AM

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;
    }
  }
0
Max
Top achievements
Rank 1
Veteran
Iron
answered on 13 May 2020, 11:39 AM

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)}}" />
0
Max
Top achievements
Rank 1
Veteran
Iron
answered on 13 May 2020, 12:04 PM

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;
    }
  }

 

0
Yoan
Telerik team
answered on 15 May 2020, 02:14 PM

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

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Tags
GridView
Asked by
Max
Top achievements
Rank 1
Veteran
Iron
Answers by
Yoan
Telerik team
Max
Top achievements
Rank 1
Veteran
Iron
Share this question
or