I have a problem where using a multi-binding to format axis labels correctly updates the labels, but does not resize correctly when the size of the labels change.
You can see the problem with this small example:
Code Behind:
If you run this example, and in the Y-axis format box enter "e" then press tab to activate, you can see the numbers correctly change to scientific notation, but now they overlap the chart!
Can you recommend something to trigger the axis to be redrawn correctly?
Thanks,
Louis
You can see the problem with this small example:
<Window x:Class="LabelTemplate_MultiBinding.MainWindow" xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" xmlns:local="clr-namespace:LabelTemplate_MultiBinding" Title="MainWindow" Height="768" Width="1024"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="*"/> <RowDefinition Height="Auto"/> </Grid.RowDefinitions> <telerik:RadCartesianChart x:Name="PropertyChart"> <telerik:RadCartesianChart.Resources> <local:ChartNumberFormatter x:Key="NumberFormatter"/> <DataTemplate x:Key="FormattedNumericAxisTemplate"> <TextBlock> <TextBlock.Text> <MultiBinding Converter="{StaticResource NumberFormatter}"> <Binding /> <Binding ElementName="PropertyChart" Path="DataContext.NumericFormat"/> </MultiBinding> </TextBlock.Text> </TextBlock> </DataTemplate> </telerik:RadCartesianChart.Resources> <telerik:RadCartesianChart.HorizontalAxis> <telerik:DateTimeCategoricalAxis/> </telerik:RadCartesianChart.HorizontalAxis> <telerik:RadCartesianChart.VerticalAxis> <telerik:LinearAxis LabelTemplate="{StaticResource FormattedNumericAxisTemplate}" /> </telerik:RadCartesianChart.VerticalAxis> <telerik:RadCartesianChart.Series> <telerik:LineSeries CategoryBinding="Date" ValueBinding="Value" ItemsSource="{Binding Path=Series1}"> </telerik:LineSeries> </telerik:RadCartesianChart.Series> </telerik:RadCartesianChart> <StackPanel Grid.Row="1" Orientation="Horizontal"> <Label>Y Axis Format:</Label> <TextBox Text="{Binding NumericFormat}" Width="200" /> </StackPanel> </Grid></Window>Code Behind:
public class MyPoint{ public DateTime Date { get; set; } public Double Value { get; set; }}public partial class MainWindow : Window, INotifyPropertyChanged{ public List<MyPoint> Series1 { get; private set; } private string _NumericFormat; public string NumericFormat { get { return _NumericFormat; } set { if (_NumericFormat != value) { _NumericFormat = value; OnPropertyChanged("NumericFormat"); } } } public MainWindow() { Series1 = new List<MyPoint>(); for (int i = 0; i < 5; i++) { DateTime date = DateTime.Today.AddDays(i); Series1.Add(new MyPoint() { Date = date, Value = i * 1000 }); } InitializeComponent(); DataContext = this; } #region INotifyPropertyChanged public event PropertyChangedEventHandler PropertyChanged; protected virtual void OnPropertyChanged(string propertyName = "") { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } } #endregion}public class ChartNumberFormatter : IMultiValueConverter{ public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture) { double number = System.Convert.ToDouble(values[0]); string format = values[1] as string; if (string.IsNullOrEmpty(format)) { return number.ToString(); } return number.ToString(format); } public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); }}If you run this example, and in the Y-axis format box enter "e" then press tab to activate, you can see the numbers correctly change to scientific notation, but now they overlap the chart!
Can you recommend something to trigger the axis to be redrawn correctly?
Thanks,
Louis
