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

Binding doesn't work in GroupBox HeaderTemplate

1 Answer 563 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Alexandre
Top achievements
Rank 1
Alexandre asked on 18 Jun 2013, 03:03 PM
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

1 Answer, 1 is accepted

Sort by
0
Alexandre
Top achievements
Rank 1
answered on 19 Jun 2013, 01:48 PM
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
Tags
General Discussions
Asked by
Alexandre
Top achievements
Rank 1
Answers by
Alexandre
Top achievements
Rank 1
Share this question
or