Binding PeriodStart and PeriodEnd

3 posts, 1 answers
  1. Tomáš Čeleda
    Tomáš Čeleda avatar
    15 posts
    Member since:
    Sep 2009

    Posted 10 Jun 2011 Link to this post

    I've got a problem with binding PeriodStart and PeriodEnd property of Silverlight control rad TimeBar. If I try to set them statically in xaml code, everything works fine. But I need to set boundaries of TimeBar dynamically. I tried trivial property binding with no success. If PeriodEnd and PeriodStart properties are in the xaml in such order like in the code snippet I get an Exception. When I try to switch the order, nothing happens and time boundaries of the timebar are not set.

     

    Here is a code snippet:

    <telerik:RadTimeBar  PeriodEnd="{Binding EndDate}" PeriodStart="{Binding StartDate}" />

    underlying ViewModel:

               private DateTime _startDate;
            public DateTime StartDate
            {
                get
                {
                    return new DateTime(2011, 1, 1);
                }
                set
                {
                    if (_startDate != value)
                    {
                        _startDate = value;
                        NotifyPropertyChanged("StartDate");
                    }
                }
            }
     
            private DateTime _endDate;
            public DateTime EndDate
            {
                get
                {
                    return new DateTime(2011, 6, 1);
                }
                set
                {
                    if (_endDate != value)
                    {
                        _endDate = value;
                        NotifyPropertyChanged("EndDate");
                    }
                }
            }

    The exception occurs when the View is bound to my ViewModel:
    System.ArgumentOutOfRangeException was unhandled by user code
      Message=The added or subtracted value results in an un-representable DateTime.
    Parameter name: value
      StackTrace:
           at System.DateTime.AddTicks(Int64 value)
           at System.DateTime.Add(Double value, Int32 scale)
           at System.DateTime.AddDays(Double value)
           at Telerik.Windows.Controls.TimeBar.WeekInterval.ExtractIntervalStart(DateTime date)
           at Telerik.Windows.Controls.TimeBar.PeriodSpanGenerator.GenerateModels(DateTime periodStart, DateTime periodEnd, Func`2 extractIntervalStartAction, Func`2 incrementAction)
           at Telerik.Windows.Controls.TimeBar.IntervalDescriptor.UpdatePeriods(DateTime periodStart, DateTime periodEnd)
           at Telerik.Windows.Controls.RadTimeBar.SynchronizeIntervalDescriptors()
           at Telerik.Windows.Controls.RadTimeBar.OnDurationChanged()
           at Telerik.Windows.Controls.RadTimeBar.OnPeriodRangePropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
           at Telerik.Windows.PropertyMetadata.<>c__DisplayClass1.<Create>b__0(DependencyObject d, DependencyPropertyChangedEventArgs e)
           at System.Windows.DependencyObject.RaisePropertyChangeNotifications(DependencyProperty dp, Object oldValue, Object newValue)
           at System.Windows.DependencyObject.UpdateEffectiveValue(DependencyProperty property, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, ValueOperation operation)
           at System.Windows.DependencyObject.RefreshExpression(DependencyProperty dp)
           at System.Windows.Data.BindingExpression.SendDataToTarget()
           at System.Windows.Data.BindingExpression.SourceAcquired()
           at System.Windows.Data.BindingExpression.System.Windows.IDataContextChangedListener.OnDataContextChanged(Object sender, DataContextChangedEventArgs e)
           at System.Windows.Data.BindingExpression.DataContextChanged(Object sender, DataContextChangedEventArgs e)
           at System.Windows.DataContextChangedEventHandler.Invoke(Object sender, DataContextChangedEventArgs e)
           at System.Windows.FrameworkElement.OnDataContextChanged(DataContextChangedEventArgs e)
           at System.Windows.FrameworkElement.OnAncestorDataContextChanged(DataContextChangedEventArgs e)
           at System.Windows.FrameworkElement.NotifyDataContextChanged(DataContextChangedEventArgs e)
           at System.Windows.FrameworkElement.OnAncestorDataContextChanged(DataContextChangedEventArgs e)
           at System.Windows.FrameworkElement.NotifyDataContextChanged(DataContextChangedEventArgs e)
           at System.Windows.FrameworkElement.OnAncestorDataContextChanged(DataContextChangedEventArgs e)
           at System.Windows.FrameworkElement.NotifyDataContextChanged(DataContextChangedEventArgs e)
           at System.Windows.FrameworkElement.OnPropertyChanged(DependencyProperty dp)
           at System.Windows.DependencyObject.RaisePropertyChangeNotifications(DependencyProperty dp, Object oldValue, Object newValue)
           at System.Windows.DependencyObject.UpdateEffectiveValue(DependencyProperty property, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, ValueOperation operation)
           at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value, Boolean allowReadOnlySet)
           at System.Windows.FrameworkElement.set_DataContext(Object value)
           at DealData.MainPage..ctor()
           at DealData.App.Application_Startup(Object sender, StartupEventArgs e)
           at MS.Internal.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args)
           at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName)

    I tried this with SL4, Q1 2011 official release and with your latest internal build 2011.1.0606. Both versions produce the same error.

    Thank you,
    Best Regards
    Tomas

  2. Answer
    Vladimir Milev
    Admin
    Vladimir Milev avatar
    1061 posts

    Posted 14 Jun 2011 Link to this post

    Hi Tomáš Čeleda,

    Try using a TwoWay binding for these properties. This is required because of the coercing of the values that happens when a binding is executed.

    Kind regards,
    Vladimir Milev
    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. DevCraft banner
  4. Tomáš Čeleda
    Tomáš Čeleda avatar
    15 posts
    Member since:
    Sep 2009

    Posted 15 Jun 2011 Link to this post

    Thank you very much. Two way binding has solved the issue.

    Best Regards,
    Tomas Celeda
Back to Top