How to Bind the Content in the Header Cell to RadGridView's DataContext
Environment
Product Version | 2019.3.917 |
Product | RadGridView for WPF |
Description
How to bind the header cells' content to properties in RadGridView's DataContext.
Solution
As the DataContext of the GridViewHeaderCell is different than the one of its parent RadGridView control, in order to bind properties of its content to such in the viewmodel, you need to use a RelativeSource binding.
<telerik:GridViewDataColumn DataMemberBinding="{Binding Name}">
<telerik:GridViewDataColumn.Header>
<TextBlock Text="{Binding DataContext.NamePropertyString, RelativeSource={RelativeSource AncestorType=telerik:RadGridView}}" />
</telerik:GridViewDataColumn.Header>
</telerik:GridViewDataColumn>