How to get a Chart Title with Centered Text and Right Aligned buttons?

5 posts, 0 answers
  1. Rodney Foley
    Rodney Foley avatar
    72 posts
    Member since:
    Oct 2009

    Posted 09 Nov 2010 Link to this post

    Okay I am trying to get my Chart's title to be centered and have some buttons that are right aligned.  However everything I try ends up having everything centered.  Below the code sample that when it is not in the chart title it works as expected (for example just in the main layout for a control). It is acting as if the ChartTitle wraps its contents inside of a StackPanel or something that prevents the expected behavior of a Grid.  

    I could swear I saw an example in the Silverlight demo page for the Chart that had a "Reload" button right aligned with a centered title but I couldn't find it when I went through them again. It must have been in a  forum post with sample code related to something else. If someone could help me work this out I would be grateful.  Thanks.

            <Grid Margin="-6">
                    <RowDefinition Height="Auto"/>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="Auto"/>
                <TextBlock TextAlignment="Center"
                    Item Summary
                <StackPanel Orientation="Horizontal"
                    <telerik:RadButton Name="exportToPng"
                            <ToolTip Content="Export to PNG"/>
                        <Image Height="16"
                    <telerik:RadButton Name="exportToExcel"
                            <ToolTip Content="Export to Excel"/>
                        <Image Height="16"
                    <telerik:RadButton Name="exportToHtml"
                            <ToolTip Content="Export to Html"/>
                        <Image Height="16"
  2. Evgeni "Zammy" Petrov
    Evgeni "Zammy" Petrov avatar
    168 posts

    Posted 12 Nov 2010 Link to this post

    Hello Rodney Foley,

     Thank you for pointing out this problem. We have fixed it internally but we missed the Q3 release, it will be out for SP1. Retemplating of the ChartTitle is needed for this to work. 

    First add this namespace:


    Put this in your control resources:
    <mscorlib:Double x:Key="ChartTitleFontSize">11</mscorlib:Double>
    <FontWeight x:Key="ChartTitleFontWeight">Bold</FontWeight>
    <SolidColorBrush x:Key="ChartTitleForeground" Color="White" />
    <Thickness x:Key="ChartTitlePadding">7</Thickness>
    <LinearGradientBrush x:Key="ChartTitleBackground"  EndPoint="0.5,1" StartPoint="0.5,0">
        <GradientStop Color="#FF5B5B5B" Offset="1"/>
        <GradientStop Color="#FF868686"/>
        <GradientStop Color="#FF4F4F4F" Offset="0.42"/>
        <GradientStop Color="#FF0E0E0E" Offset="0.43"/>
    <Thickness x:Key="ChartTitleBorderThickness">1</Thickness>
    <SolidColorBrush x:Key="ChartTitleBorderBrush" Color="#FFB5B5B5" />
    <Thickness x:Key="ChartTitleOuterBorderThickness">1</Thickness>
    <SolidColorBrush x:Key="ChartTitleOuterBorderBrush" Color="Black" />
    <Style  x:Key="CustomTitle2" TargetType="telerik:ChartTitle">
        <Setter Property="HorizontalContentAlignment" Value="Center" />
        <Setter Property="Background" Value="{StaticResource ChartTitleBackground}" />
        <Setter Property="BorderBrush" Value="{StaticResource ChartTitleBorderBrush}" />
        <Setter Property="OuterBorderBrush" Value="{StaticResource ChartTitleOuterBorderBrush}" />
        <Setter Property="BorderThickness" Value="{StaticResource ChartTitleBorderThickness}" />
        <Setter Property="OuterBorderThickness" Value="{StaticResource ChartTitleOuterBorderThickness}" />
        <Setter Property="Padding" Value="{StaticResource ChartTitlePadding}" />
        <Setter Property="Foreground" Value="{StaticResource ChartTitleForeground}" />
        <Setter Property="FontSize" Value="{StaticResource ChartTitleFontSize}" />
        <Setter Property="FontWeight" Value="{StaticResource ChartTitleFontWeight}" />
        <Setter Property="Template">
                <ControlTemplate TargetType="telerik:ChartTitle">
                    <Border BorderThickness="{TemplateBinding OuterBorderThickness}"
                          BorderBrush="{TemplateBinding OuterBorderBrush}">
                             Background="{TemplateBinding Background}"
                             BorderBrush="{TemplateBinding BorderBrush}"
                             BorderThickness="{TemplateBinding BorderThickness}"
                             CornerRadius="{TemplateBinding CornerRadius}">
                            <ContentControl HorizontalContentAlignment="Stretch"
                                HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                Content="{TemplateBinding Content}"
                                Margin="{TemplateBinding Padding}"
                                Foreground="{TemplateBinding Foreground}"
                                FontSize="{TemplateBinding FontSize}"
                                FontStyle="{TemplateBinding FontStyle}" 
                                FontWeight="{TemplateBinding FontWeight}"
                                FontFamily="{TemplateBinding FontFamily}" />

    after that just change the ChartTitle xaml to this:
    <telerik:ChartTitle HorizontalContentAlignment="Stretch" Style="{StaticResource CustomTitle2}">

    I hope this gets you started properly.

    Best wishes,
    Evgeni "Zammy" Petrov
    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. Rodney Foley
    Rodney Foley avatar
    72 posts
    Member since:
    Oct 2009

    Posted 12 Nov 2010 Link to this post

    Hi Zammy,

    That is great news that it will be fixed in Q3 SP1.  Also thanks for putting together a style workaround, unfortunately it is not working for me.  I placed it in the UserControl.Resources and added the static reference to it as you specified, and nothing changed.  Do I need to change how I use the Grid in the title or switch to something else as well?  I looked through the style and I am not sure where the fix is within it, it doesn't look like it is changing the type of container, just trying to change the container settings. However if the container is not one that is designed to fill space like a StackPanel then until it is changed to be a different container there is no style that can fix it.  At least that I can come up with, using my limited knowledge of styles.

    Any additional help on a work around would be appreciated.

    Kind Regards,

  4. Rodney Foley
    Rodney Foley avatar
    72 posts
    Member since:
    Oct 2009

    Posted 12 Nov 2010 Link to this post

    I resolved the issue without overriding the style.  (I still can't wait for the fix to make this easier.)

    Basically I reverted the title to just be text instead of a series of controls.  I then moved the stack panel of buttons out and put it under the Chart in the XAML to give it a higher Z-Order than the chart, I then put the stack panel in to the same Grid Cell (same row/column) and positioned at the top right.  This overlays it right where I want, and it hugs this location on resizing and looks good.

    Kind Regards,

  5. Grégory
    Grégory avatar
    21 posts
    Member since:
    Mar 2011

    Posted 12 Apr 2011 Link to this post


    I had the same issue. With Q1 2011, is resolved. Thank you!
Back to Top