Binding doesn't work in GroupBox HeaderTemplate

2 posts, 0 answers
  1. Alexandre
    Alexandre avatar
    8 posts
    Member since:
    Feb 2012

    Posted 18 Jun 2013 Link to this post

    Hi,

    Binding doesn't seem to work in the HeaderTemplate of the GroupBox control.

    I can bind the Header property but not the content in HeaderTemplate. The header is blank.

    Here is my XAML:
    <UserControl x:Class="SilverlightApplication4.MainPage"
        mc:Ignorable="d"
        d:DesignHeight="300" d:DesignWidth="400">
     
      <Grid x:Name="LayoutRoot" Background="White">
        <telerik:GroupBox Margin="10">
          <telerik:GroupBox.HeaderTemplate>
            <DataTemplate>
              <TextBlock Text="{Binding sHeader}" />
            </DataTemplate>
          </telerik:GroupBox.HeaderTemplate>
        </telerik:GroupBox>
      </Grid>
    </UserControl>

    Here is the code behind:
    using System.Windows.Controls;
     
    namespace SilverlightApplication4
    {
      public partial class MainPage : UserControl
      {
        public string sHeader { get; set; }
     
        public MainPage()
        {
          InitializeComponent();
     
          sHeader = "My Header";
          this.LayoutRoot.DataContext = this;
        }
      }
    }

    The header doesn't appear.

    If I use the Header property instead of the HeaderTemplate, it works:
    <UserControl x:Class="SilverlightApplication4.MainPage"
        mc:Ignorable="d"
        d:DesignHeight="300" d:DesignWidth="400">
     
      <Grid x:Name="LayoutRoot" Background="White">
        <telerik:GroupBox Margin="10" Header="{Binding sHeader}">
        </telerik:GroupBox>
      </Grid>
    </UserControl>

    Also If I bind to a static resource it works.

    Is this an issue or a normal behavior?

    Eventually I will have to use the HeaderTemplate property to set a more complex header.

    Thanks,

    Alex
  2. Alexandre
    Alexandre avatar
    8 posts
    Member since:
    Feb 2012

    Posted 19 Jun 2013 Link to this post

    Ok. Found it. It's my mistake. I should have used the Header property and not the HeaderTemplate property.

    <telerik:GroupBox>
      <telerik:GroupBox.Header>
        <StackPanel>
          <TextBlock Text="{Binding sHeader}" />
        </StackPanel>             
      </telerik:GroupBox.Header>
    </telerik:GroupBox>

    Thanks anyway.

    Alex
  3. DevCraft banner
Back to Top