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

HierarchyChildTemplate Header Binding Issuse

5 Answers 58 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Shay
Top achievements
Rank 1
Shay asked on 11 Oct 2013, 11:53 AM
Hi,

I am using a HierarchyChildTemplate in which I have bound the Header to our language file attempting to extract the correct header for the column.

In the case of a standard RadGridView the implementation works perfectly fine and I get the column header in the desired language

In the case of the HierarchyChildTemplate using the exact same solution results in the Column Header displaying the Path variable name of the bound DataMemberBinding instead?

I have tried a number of different binding solutions for the header however is seems Binding does not work.

Has anyone else experienced the same issues? or have a working example?  

 

5 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 14 Oct 2013, 05:50 AM
Hello Shay,

DataContext of the grid inside hierarchyChildTemlate is the data item of the corresponding row, rather than the same as the main grid. So, that might be the cause of the problem. How do you bind the headers of the columns ?  

Regards,
Maya
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Shay
Top achievements
Rank 1
answered on 14 Oct 2013, 12:06 PM
Hi,

Here are a couple of different examples.

1. Binding to an Static Resource XML language file. This binding works fine in the main table but not in the HierarchyChildTemplate. 

    <Page.Resources>
        <ResourceDictionary>
            <XmlDataProvider x:Key="Lang" Source="/Common/Lang/Swedish.xml" XPath="Retail.POS"/>
            <converters:CustomerOrderStatusIdToNameConverter x:Key="CustomerOrderStatusIdToName" />
            <converters:CustomerOrderPaymentStatusIdToNameConverter x:Key="CustomerOrderPaymentStatusIdToNameConverter" />
            <converters:CustomerTypeIdToNameConverter x:Key="CustomerTypeIdToNameConverter" />
        </ResourceDictionary>
    </Page.Resources>

<telerik:GridViewDataColumn Width="80" DataMemberBinding="{Binding Path=AttributeValue1}" Name="Attribute1Sorted" Header="{Binding Source={StaticResource Lang}, XPath=CustomerOrderWatcher/AttributeHeader1/@Value}" IsVisible="True"/>

2. Binding to the ViewModel using RelativeSource and FindAncestor

<telerik:GridViewDataColumn Width="80" DataMemberBinding="{Binding Path=AttributeValue1}" Name="Attribute1Sorted" Header="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Page}}, Path=DataContext.Attribute1Header, UpdateSourceTrigger=PropertyChanged, Mode=OneWay}" IsVisible="True"/>


In both cases and a number of different variations of case 2 when {Binding} is used on the Header the text that is displayed on the Header is 'AttributeValue1'

Shay

0
Maya
Telerik team
answered on 14 Oct 2013, 01:30 PM
Hello Shay, 

Could you try setting the Source of the binding through StaticResource? For example:

<telerik:GridViewDataColumn Width="80" DataMemberBinding="{Binding Path=AttributeValue1}" Name="Attribute1Sorted" Header="{Binding Attribute1Header, Source={StaticResource MyViewModel}, UpdateSourceTrigger=PropertyChanged, Mode=OneWay}" IsVisible="True"/>
 
Do you get the same behavior ?

Regards,
Maya
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Shay
Top achievements
Rank 1
answered on 17 Oct 2013, 12:20 PM
Hi Maya,

I have tested your suggestion and was able to get it working. However this is not exactly an optimal solution as we are using injection with our ViewModels.

Thanks Shay

 
0
Maya
Telerik team
answered on 18 Oct 2013, 07:04 AM
Hello Shay,

DataContext of the child grid is the corresponding parent data item. And if you try to bind to a property that is not in this context (as it is in this case - in the context of the main grid), you will get binding errors in the Output window and nothing will be displayed. You need to make sure that the source of the binding is known and it is the one where this property is.   

Regards,
Maya
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
GridView
Asked by
Shay
Top achievements
Rank 1
Answers by
Maya
Telerik team
Shay
Top achievements
Rank 1
Share this question
or