Databinding GridViewDataColumn and the group-by functionality

4 posts, 0 answers
  1. Richard
    Richard avatar
    8 posts
    Member since:
    Mar 2015

    Posted 30 Sep Link to this post

    Hello group, 

    Question: I have a GridViewDataColumn. The Header property has been bind to an property in the ViewModel. If you now in the UI drag the column header to the group-by bar the Grid will display the name of the group-by as: [DataContextName].[PropertyName] instead of the (string) value of the property of the binding. 

    I have tried to use an converter to collect the string form the resource file but this does not work either. 

    Help would be appriciated. 

    Richard

  2. Stefan X1
    Admin
    Stefan X1 avatar
    514 posts

    Posted 04 Oct Link to this post

    Hello Richard,

    Would it be possible for you to demonstrate the exact steps to reproduce such behavior, as I am not able to do so locally? Sharing some code would also be quite useful.

    Thanks in advance for your cooperation.

    Regards,
    Stefan X1
    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Richard
    Richard avatar
    8 posts
    Member since:
    Mar 2015

    Posted 07 Oct in reply to Stefan X1 Link to this post

    In my XAML I bind the property ContentTemplate to the property ChargeCodeColumnHeader in my Viewmodel.
    XAML looks like this:

    <telerik:GridViewDataColumn DataMemberBinding="{Binding PerformedActivityOverviewItem.ChargeCode}"
     Width="100">
     <telerik:GridViewDataColumn.HeaderCellStyle>
     <Style TargetType="telerik:GridViewHeaderCell">
     <Setter Property="ContentTemplate">
     <Setter.Value>
     <DataTemplate>
     <TextBlock Text="{Binding DataContext.ChargeCodeColumnHeader, ElementName=Root}"
     TextWrapping="Wrap" />
     </DataTemplate>
     </Setter.Value>
     </Setter>
     </Style>
     </telerik:GridViewDataColumn.HeaderCellStyle>
    </telerik:GridViewDataColumn>

    The Viewmodel property:

    public string ChargeCodeColumnHeader
    {
        get
           {
             return (AddOnMedicationOnly) ? CommonResources.ZINumberColumn :   CommonResources.WrappedChargeCodeColumn;
           }
    }

    Now the page the column header displays the name correct (taken from the resource file). However if you drag the column header to the group-by banner you will see:
    PerformedActivityOverviewItem.ChargeCode
    this is the Datacontext.property name instead of the value of ChargeCodeColumnHeader.

    How can I display the value of ChargeCodeColumnHeader property?

    Thanks in advance.

  5. Stefan X1
    Admin
    Stefan X1 avatar
    514 posts

    Posted 12 Oct Link to this post

    Hello Richard,

    The reported behavior is due to the DataContext of the column header. It is not the same as the one of the column and needs to be explicitly set. Please take a look at this forum thread for further reference.

    Best Regards,
    Stefan X1
    Telerik by Progress
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Back to Top