Header Binding

7 posts, 0 answers
  1. Stephen
    Stephen avatar
    14 posts
    Member since:
    Jul 2010

    Posted 21 Jul 2010 Link to this post

     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
  2. Stefan Dobrev
    Admin
    Stefan Dobrev avatar
    790 posts

    Posted 26 Jul 2010 Link to this post

    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
  3. DevCraft banner
  4. Ryan Abbott
    Ryan Abbott avatar
    9 posts
    Member since:
    Jul 2007

    Posted 26 Jul 2010 Link to this post

    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.
  5. Stefan Dobrev
    Admin
    Stefan Dobrev avatar
    790 posts

    Posted 28 Jul 2010 Link to this post

    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
  6. Ryan Abbott
    Ryan Abbott avatar
    9 posts
    Member since:
    Jul 2007

    Posted 02 Aug 2010 Link to this post

    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?
  7. Stefan Dobrev
    Admin
    Stefan Dobrev avatar
    790 posts

    Posted 04 Aug 2010 Link to this post

    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
  8. Marjorie
    Marjorie avatar
    4 posts
    Member since:
    Sep 2010

    Posted 07 Dec 2010 Link to this post

    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>
     

     

     

     

     

     



Back to Top
DevCraft banner