This is a migrated thread and some comments may be shown as answers.
Header Binding
6 Answers 64 Views
This is a migrated thread and some comments may be shown as answers.
Stephen
Top achievements
Rank 1
Stephen asked on 21 Jul 2010, 05:59 PM
 I've been struggling with binding on the Header property of a GridViewDataColumn all day. If I hard-code the Header it appears, but if I use a binding to set the Header the binding is ignored and the property name used for the binding in the DataMemberBinding is displayed instead.

 How can I set the Headers in my TreeListView using data binding?

 Cheers,
 Steve

6 Answers, 1 is accepted

Sort by
0
Stefan Dobrev
Telerik team
answered on 26 Jul 2010, 05:25 PM
Hello Stephen,

You cannot data bind the header property of the columns. What you can do is to place a TextBlock for example in the Header and databind its Text property. Note that you should use a binding with a source defined because there is no DataContext for the header cells.

Regards,
Stefan Dobrev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Ryan Abbott
Top achievements
Rank 1
answered on 26 Jul 2010, 09:50 PM
Could you provide an example of this? I've been trying to do what you explained, but it is not putting text into the Header.

I have:
<TextBox Text="{Binding Title}" />
 
<telerik:GridViewDataColumn.Header>
    <TextBlock Text="{Binding Title }"/>
</telerik:GridViewDataColumn.Header>

and the TextBox that is not in the Header will display the Title, but TextBlock in the Header will not display anything.
0
Stefan Dobrev
Telerik team
answered on 28 Jul 2010, 05:13 PM
Hi Ryan,

You should specify the Source of the binding in order for this to work. Here is a sample snippet that does this:
<UserControl.Resources>
    <sys:String x:Name="Header">My Header</sys:String>
...
 
<telerik:GridViewDataColumn.Header>
    <TextBlock Text="{Binding Source={StaticResource Header}}"/>
</telerik:GridViewDataColumn.Header>
 
...

Sincerely yours,
Stefan Dobrev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Ryan Abbott
Top achievements
Rank 1
answered on 02 Aug 2010, 10:20 PM
Thanks, but I'm looking for a way to use a non-static source for the databinding. Is this possible?

For example, I'm binding the control to a ViewModel, and when I do this, it displays the records in the TreeListView:

<telerik:RadTreeListView x:Name="TreeListView"
  AutoGenerateColumns="False"
  IsReadOnly="True"
  ItemsSource="{Binding ListData}"
  SelectedItem="{Binding SelectedNode, Mode=TwoWay}">
  <telerik:RadTreeListView.Columns>
    <telerik:GridViewDataColumn UniqueName="ColTitle" DataMemberBinding="{Binding Title}">
      <telerik:GridViewDataColumn.Header>
        <TextBlock Text="The Column Title" />
      </telerik:GridViewDataColumn.Header>
    </telerik:GridViewDataColumn>
  </telerik:RadTreeListView.Columns>
</telerik:RadTreeListView>

So, I'm binding ListData which is an ObservableCollection of a class that contains the data I want. It's a property in the ViewModel, and in doing this it binds the data perfectly. However, the Header will be a static "The Column Title". There is another property in the ViewModel called DisplayOptions. What I want to do his have the TextBlock.Text bind from the DisplayOptions property of the ViewModel, specifically, the DisplayOptions.Title field (which is a string). This is what I tried to do, but it does not work:

<telerik:RadTreeListView x:Name="TreeListView"
  AutoGenerateColumns="False"
  IsReadOnly="True"
  ItemsSource="{Binding ListData}"
  SelectedItem="{Binding SelectedNode, Mode=TwoWay}">
  <telerik:RadTreeListView.Columns>
    <telerik:GridViewDataColumn UniqueName="ColTitle" DataMemberBinding="{Binding Title}">
      <telerik:GridViewDataColumn.Header>
        <TextBlock Text="{Binding DisplayOptions.Title}" />
      </telerik:GridViewDataColumn.Header>
    </telerik:GridViewDataColumn>
  </telerik:RadTreeListView.Columns>
</telerik:RadTreeListView>

I've tried various versions of {Binding}, but none work with this. Any idea why this is not working, or what I am doing wrong?
0
Stefan Dobrev
Telerik team
answered on 04 Aug 2010, 10:40 AM
Hello Ryan,

This is currently not supported by the Silverlight framework. There are ways (hacks) to make this work with via HeaderCellStyle property or data context proxies but they are highly not recommended.

Regards,
Stefan Dobrev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Marjorie
Top achievements
Rank 1
answered on 07 Dec 2010, 08:40 PM
When will this be supported? It is very common for us to bind the form's data context to a ModelView class. Then set the GridView's ItemSource to an ObservableCollection located inside that ModelView class. And of course this all works just fine.

Now we want the GridView control to be smart enough to have all headers bind to the form's data context which is the ModelView class.

I tried the approach defined here http://www.telerik.com/community/forums/silverlight/gridview/binding-header-text.aspx ; however, I get an error in XAML stating it cannot create an instance of my ModelView class. i.e.

<UserControl.Resources>
    <ViewModel:PayTypesViewModel x:Key="myViewModel" />
</UserControl.Resources>
 

 

 

 

 

 



Asked by
Stephen
Top achievements
Rank 1
Answers by
Stefan Dobrev
Telerik team
Ryan Abbott
Top achievements
Rank 1
Marjorie
Top achievements
Rank 1
Share this question
or