Hi,
I'm trying to make a bar chart with long text of categories, so I wrapped them all by the following code
xaml
<Grid SizeChanged="Grid_SizeChanged"> <telerik:RadCartesianChart Grid.Row="0" x:Name="ChartSeries" > <telerik:RadCartesianChart.HorizontalAxis> <telerik:CategoricalAxis ClipToBounds="False" HorizontalLocation="Right" SmartLabelsMode="SmartStep" IsStepRecalculationOnZoomEnabled="True"> <telerik:CategoricalAxis.LabelTemplate> <DataTemplate> <TextBlock TextWrapping="Wrap" MaxWidth="{Binding ElementName=Self, Path=MaxWidthTextBlock}" Text="{Binding}" /> </DataTemplate> </telerik:CategoricalAxis.LabelTemplate> </telerik:CategoricalAxis> </telerik:RadCartesianChart.HorizontalAxis> <telerik:RadCartesianChart.VerticalAxis> <telerik:LinearAxis Minimum="0" RangeExtendDirection="Positive" SmartLabelsMode="SmartStep" > </telerik:LinearAxis> </telerik:RadCartesianChart.VerticalAxis> <telerik:BarSeries ShowLabels="False" ClipToPlotArea="False"> <telerik:BarSeries.DataPoints> <telerik:CategoricalDataPoint Category="TextTextTextTextTextTextText" Value="2" /> <telerik:CategoricalDataPoint Category="TextTextTextTextTextTextTextTextText" Value="5" /> <telerik:CategoricalDataPoint Category="TextTextTextTextTextTextTextTextTextText" Value="3" /> <telerik:CategoricalDataPoint Category="TextTextTextText" Value="10" /> <telerik:CategoricalDataPoint Category="TextTextTextTextTextTextTextTextTextTextTextTextText" Value="9" /> <telerik:CategoricalDataPoint Category="TextTextTextText" Value="7" /> <telerik:CategoricalDataPoint Category="TextTextTextText" Value="1" /> </telerik:BarSeries.DataPoints> </telerik:BarSeries> <telerik:RadCartesianChart.Grid> <telerik:CartesianChartGrid MajorLinesVisibility="Y" x:Name="Line"> <telerik:CartesianChartGrid.MajorYLineStyle> <Style TargetType="Line"> <Setter Property="Stroke" Value="DarkGray"/> </Style> </telerik:CartesianChartGrid.MajorYLineStyle> </telerik:CartesianChartGrid> </telerik:RadCartesianChart.Grid> </telerik:RadCartesianChart> </Grid>As you can see, I have a method to recalculate the maxwidth of textblock when the container's size is change(Grid) as the following code behind
private void Grid_SizeChanged(object sender, SizeChangedEventArgs e) { if(e.PreviousSize.Width != 0) { var ratio = e.NewSize.Width / e.PreviousSize.Width; MaxWidthTextBlock *= ratio; } }The calculation seems to compute correctly for max width of the textblock but the position of the label is not correct. It seems to be a bit right aligned.
Do you have any idea to make it center as before windows size is changed, please advise ?
I also attached the image for before / after windows size change. Best Regards,
Witt
