This is a migrated thread and some comments may be shown as answers.

Error when setting both the SelectionStart and SelectionEnd within the viewmodel

1 Answer 86 Views
TimeBar
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Joe
Top achievements
Rank 1
Joe asked on 08 Aug 2012, 09:25 PM
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);
or
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;
            }
            else
            {
                SelectionEnd = endDt;
                SelectionStart = startDt;
            }
        }



Here is the Xaml.

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

telerik:StyleManager.Theme="Office_Blue"

Background="Transparent"

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}"

 

IsSnapToIntervalEnabled="False"

 

VisiblePeriodChanged="TimeBarVisiblePeriodChanged"

 

>


Here are the view model properties.

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

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

 

 


1 Answer, 1 is accepted

Sort by
0
Tsvetie
Telerik team
answered on 13 Aug 2012, 12:56 PM
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].

Regards,
Tsvetie
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
TimeBar
Asked by
Joe
Top achievements
Rank 1
Answers by
Tsvetie
Telerik team
Share this question
or