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

SelectionChanged with EventToCommand

2 Answers 202 Views
Calendar
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Valentin
Top achievements
Rank 1
Valentin asked on 23 Apr 2013, 07:07 PM
Hi,

I'm currently developing a Windows Phone 8 application and I use your RadCalendar control.
The application is created with the MVVM Light Framework.

The problem occurs when I try to detect the SelectedValueChanged using the EventToCommand trigger. It's seems to occurs before the binding value changed.

XAML:
<telerikInput:RadCalendar x:Name="Calendar" SelectedValue="{Binding CalendarSelectedDate, Mode=OneWay}" GridLinesBrush="{StaticResource ElementBackgroundColor}" MonthInfoDisplayMode="Small" IsTodayHighlighted="True" >
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="SelectedValueChanged">
            <command:EventToCommand Command="{Binding CalendarSelectedDateChanged, Mode=OneWay}" />
        </i:EventTrigger>
    </i:Interaction.Triggers>
</telerikInput:RadCalendar>

public DateTime? CalendarSelectedDate { get; set; }
 
public ICommand CalendarSelectedDateChanged { get; set; }
 
public MainViewModel(IDataService dataService)
{
    CalendarSelectedDateChanged = new RelayCommand(FilterSession);
}
 
private void FilterSession()
{
    // ommited code
}

In the FilterSession, when I access the CalendarSelectedDate for the first the value is null and in the next selections it's the old value.

If you could take a look to the code and tell me if it's a normal behavior, or if there is a work around when using EventToCommand.

Kinds Regards.

Update : This should be in the Windows Phone 8 RadCalendar Thread, sorry about this...

2 Answers, 1 is accepted

Sort by
0
Accepted
Todor
Telerik team
answered on 26 Apr 2013, 12:08 PM
Hi Valentin,

Thank you for writing.

Yes, this is the expected behavior, as the binding gets evaluated after the event is fired. In order to get the new value, you can use the RelayCommand implementation with a parameter, by applying the following modifications:
public MainViewModel()
{
    CalendarSelectedDateChanged = new RelayCommand<ValueChangedEventArgs<object>>(FilterSession);
}
 
private void FilterSession(object parameter)
{
    ValueChangedEventArgs<object> args = (ValueChangedEventArgs<object>)parameter;
    DateTime? newValue = args.NewValue as DateTime?;
 
    // ommited code
}

Just make sure that you set the EventToCommand's PassEventArgsToCommand property to true in order to pass the ValueChangedEventArgs as a parameter.

I hope this information helps.

All the best,
Todor
the Telerik team
Have a suggestion or face a problem - you can use the Ideas & Feedback portal to submit ideas, feedback and vote for them.
0
Valentin
Top achievements
Rank 1
answered on 26 Apr 2013, 05:23 PM
Thanks a lot, it work like a charm!
Tags
Calendar
Asked by
Valentin
Top achievements
Rank 1
Answers by
Todor
Telerik team
Valentin
Top achievements
Rank 1
Share this question
or