Error when setting both the SelectionStart and SelectionEnd within the viewmodel

2 posts, 0 answers
  1. Joe
    Joe avatar
    31 posts
    Member since:
    Apr 2012

    Posted 08 Aug 2012 Link to this post

    I would like to be able to set the selection start and selection end in my view modle.   I can change one or the other but If I change both I get the following error --

    {System.ArgumentException: '0' is not a valid value for property 'System.Windows.CustomDependencyProperty'.
       at Telerik.Windows.PropertyMetadata.PropertyChangeHook.OnPropertyChanged(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.SourcePropertyChanged(PropertyPathListener sender, PropertyPathChangedEventArgs args)
       at System.Windows.PropertyPathListener.ReconnectPath()
       at System.Windows.Data.Debugging.BindingBreakPoint.<>c__DisplayClass4.<BreakOnSharedType>b__3()}

    The error is occuring when I call the OnPropertyChanged for either the SelectionStart or SelectionEnd.  And does not happen every time.  Very random.

    OnPropertyChanged(() => SelectionStart);
    OnPropertyChanged(() => SelectionEnd);

    This is what I am trying to do. <-- notice I am even trying to be sure that the startDate is never greater than the endDate of the RadTimeBar.

            private void SetSelectionDates(DateTime value)
                TimeSpan ts = _selectionEnd - _selectionStart;
                int days = ts.Days;

                DateTime startDt = value;
                DateTime endDt = value.AddDays(days).AddHours(_selectionEnd.Hour).AddMinutes(_selectionEnd.Minute).AddSeconds(_selectionEnd.Second);
                bool doSelectionStartFirst = (_selectionEnd >= value);

                if (doSelectionStartFirst)
                    SelectionStart = startDt;
                    SelectionEnd = endDt;
                    SelectionEnd = endDt;
                    SelectionStart = startDt;

    Here is the Xaml.

    <telerik:RadTimeBar x:Name="TimeBar" Margin="2" Grid.ColumnSpan="2"



    PeriodStart="{Binding PeriodStart, Mode=TwoWay}"

    PeriodEnd="{Binding PeriodEnd, Mode=TwoWay}"

    VisiblePeriodStart="{Binding VisiblePeriodStart, Mode=TwoWay}"

    VisiblePeriodEnd="{Binding VisiblePeriodEnd, Mode=TwoWay}"

    SelectionEnd="{Binding SelectionEnd, Mode=TwoWay}"

    SelectionStart="{Binding SelectionStart, Mode=TwoWay}"


    MinSelectionRange="{Binding MinSelectionRange, Mode=TwoWay}"

    MaxSelectionRange="{Binding MaxSelectionRange, Mode=TwoWay}"


    MinZoomRange="{Binding MinZoomRange, Mode=TwoWay}"







    Here are the view model properties.

            private DateTime _selectionStart;
            public DateTime SelectionStart
                get { return _selectionStart; }
                    _selectionStart = value;
                    OnPropertyChanged(() => SelectionStart);

            private DateTime _selectionEnd;
            public DateTime SelectionEnd
                get { return _selectionEnd; }
                    _selectionEnd = value;
                    OnPropertyChanged(() => SelectionEnd);



  2. Tsvetie
    Tsvetie avatar
    1517 posts

    Posted 13 Aug 2012 Link to this post

    Hi Craig,

    I am not aware of such problem that occurs randomly. Could you please open a formal support ticket and send me a simple running project, demonstrating this exception?

    I have attached to this thread my test page for your reference.

    In the meantime, please make sure that the values you set to SelectionStart and SelectionEnd are within the range [PeriodStart; PeriodEnd].

    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top