Binding to DateTimeContinuousAxis.Maximum

5 posts, 0 answers
  1. Geoffrey
    Geoffrey avatar
    16 posts
    Member since:
    Mar 2011

    Posted 21 Feb 2012 Link to this post

    I am trying to bind to the DateTimeContinusousAxis.Maximum property in xaml but when I do it throws an exception. Is this possible?
  2. Yavor
    Admin
    Yavor avatar
    401 posts

    Posted 24 Feb 2012 Link to this post

    Hi Geoffrey,

    We have made DateTimeContinusousAxis.Maximum property a dependency property for the Q1 release. Before that it was a regular property and binding it will throw an exception, since bindings are only supported on dependency property.

    All the best,
    Yavor
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  3. DevCraft banner
  4. MikeWiese
    MikeWiese avatar
    41 posts
    Member since:
    Apr 2007

    Posted 26 Jun 2012 Link to this post

    So how would you write code to programatically bind a viewmodel property to an axis min or max?
  5. Giuseppe
    Admin
    Giuseppe avatar
    2363 posts

    Posted 29 Jun 2012 Link to this post

    Hello Mike,

    Here is a sample code snippet to get you started:

    XAML
    <telerik:RadCartesianChart x:Name="RadChart1" />

    C#
    using System;
    using System.Collections.Generic;
    using System.Windows.Controls;
    using System.Windows.Data;
    using Telerik.Windows.Controls;
    using Telerik.Windows.Controls.ChartView;
     
    namespace SilverlightApplication15
    {
        public partial class MainPage : UserControl
        {
            public MainPage()
            {
                InitializeComponent();
     
                this.DataContext = new ViewModel();
     
                DateTimeContinuousAxis horizontalAxis = new DateTimeContinuousAxis() { LabelFormat = "dd/MM/yyyy" };
                horizontalAxis.SetBinding(DateTimeContinuousAxis.MinimumProperty, new Binding("AxisMinimum"));
                RadChart1.HorizontalAxis = horizontalAxis;
     
                RadChart1.VerticalAxis = new LinearAxis();
     
                BarSeries series = new BarSeries();
                series.CategoryBinding = new PropertyNameDataPointBinding("Date");
                series.ValueBinding = new PropertyNameDataPointBinding("Value");
                series.ItemsSource = (this.DataContext as ViewModel).Data;
     
                RadChart1.Series.Add(series);
            }
        }
     
        public class ViewModel : ViewModelBase
        {
            private Random rand = new Random(123456);
            private List<ChartData> _data;
            private DateTime _axisMinimum;
     
            public ViewModel()
            {
                this.Data = this.GetData();
                this.AxisMinimum = DateTime.Today.AddDays(-10);
            }
     
            public List<ChartData> Data
            {
                get
                {
                    return this._data;
                }
                set
                {
                    if (this._data != value)
                    {
                        this._data = value;
                        this.OnPropertyChanged("Data");
                    }
                }
            }
     
            public DateTime AxisMinimum
            {
                get
                {
                    return this._axisMinimum;
                }
                set
                {
                    if (this._axisMinimum != value)
                    {
                        this._axisMinimum = value;
                        this.OnPropertyChanged("AxisMinimum");
                    }
                }
            }
     
            private List<ChartData> GetData()
            {
                List<ChartData> data = new List<ChartData>();
                for (int i = 0; i < 10; i++)
                {
                    data.Add(new ChartData() { Date = DateTime.Today.AddDays(i), Value = rand.Next(10, 100) });
                }
     
                return data;
            }
        }
     
        public class ChartData
        {
            public DateTime Date
            {
                get;
                set;
            }
     
            public double Value
            {
                get;
                set;
            }
        }
    }

    Hope this helps.


    Greetings,
    Giuseppe
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  6. MikeWiese
    MikeWiese avatar
    41 posts
    Member since:
    Apr 2007

    Posted 29 Jun 2012 Link to this post

    Thank you Giuseppe
Back to Top
DevCraft banner