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

Cannot change LabelStyle in runtime

3 Answers 82 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
Jesper
Top achievements
Rank 1
Jesper asked on 31 Aug 2012, 06:55 AM
Hello,

In my project I have a need for printing the currently presented chart. I do this by simply rendering the chart into an image in memory but the on-screen colors are not fit for a white (paper) background so I need to change some of them before the rendering starts. 

The chart is a RadCartesianChart and this is the part of it that declares the Horizontal axis:

<telerik:RadCartesianChart.HorizontalAxis>
    <telerik:DateTimeCategoricalAxis
            LabelTemplate="{StaticResource _dateTimeLabelTemplate}"
            LabelFitMode="Rotate"
            LabelStyle="{StaticResource HmiChartLabelStyle}"
            LineStroke="{StaticResource HmiForeColor3Brush}"
            >
        <telerik:DateTimeCategoricalAxis.MajorTickStyle>
            <Style TargetType="Rectangle">
                <Setter Property="Fill" Value="{StaticResource HmiForeColor3Brush}" />
            </Style>
        </telerik:DateTimeCategoricalAxis.MajorTickStyle>
    </telerik:DateTimeCategoricalAxis>
</telerik:RadCartesianChart.HorizontalAxis>

As a side note I would like to mention that I have also tried the MVVM approach and bound the LabelStyle to the view model but according to this thread that is currently not possible due to a bug that is scheduled to be fixed in a later update.

So, with the above declaration refering to a static resource I later prepare the chart for hard copy rendering like this:

private static void prepareChartForRendering(RadCartesianChart chart, out object restoreState)
{
    var chartState = new ChartState
                       {
                           LabelStyle = chart.HorizontalAxis.LabelStyle,
                           PanAndZoomBehavior = chart.Behaviors.FirstOrDefault(child => child is ChartPanAndZoomBehavior) as ChartPanAndZoomBehavior
                       };
    chart.HorizontalAxis.LabelStyle = HmiResources.HmiPrintedChartLabelStyle;
    if (chartState.PanAndZoomBehavior != null)
        chart.Behaviors.Remove(chartState.PanAndZoomBehavior);
    restoreState = chartState;
}

The 'HmiPrintedChartLabelStyle' referred to specifies a black Foreground color but the rendered chart is still rendered with its white labels. While experimenting with the chart's behavior I tried to omit the restoration of the chart LabelStyle after the hard copy rendering and it seems I cannot affect the LabelStyle at all: It's still white, even on screen, after I have changed the LabelStyle to a black font.

How do I go about changing the LabelStyle at runtime?

Thanks

3 Answers, 1 is accepted

Sort by
0
Jesper
Top achievements
Rank 1
answered on 31 Aug 2012, 06:58 AM
I just realized I posted in the Silverlight branch whereas my project is WPF. I don't know if there's any technincal difference but feel free to move the post to the WPF>ChartView branch.
0
Accepted
Petar Marchev
Telerik team
answered on 04 Sep 2012, 08:21 AM
Hi Jesper,

The RadChartView supports export and print for a fully rendered chart. If you change a text box style and you try to export it right away - it just might not work, because a layout pass has not occured.
 
I have created a simple project based on your code and explanations. It exports a chart on the click of a button.In this event handler, the LabelStyle property of the horizontal axis is changed, then the chart is exported and then the LabelStyle is set to its original value. Do examine the attached project and see if this is what you are trying to achieve. If not, you can update the project accordingly to demonstrate the issues you are experiencing and open a new support ticket and attach the project to it. 

All the best,
Petar Marchev
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Jesper
Top achievements
Rank 1
answered on 12 Sep 2012, 09:10 PM
Forcing a layout pass did the trick. Thank you!
Tags
ChartView
Asked by
Jesper
Top achievements
Rank 1
Answers by
Jesper
Top achievements
Rank 1
Petar Marchev
Telerik team
Share this question
or