SelectionChanged with EventToCommand

3 posts, 1 answers
  1. Valentin
    Valentin avatar
    2 posts
    Member since:
    Apr 2013

    Posted 23 Apr 2013 Link to this post

    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. Answer
    Todor
    Admin
    Todor avatar
    778 posts

    Posted 26 Apr 2013 Link to this post

    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.
  3. DevCraft banner
  4. Valentin
    Valentin avatar
    2 posts
    Member since:
    Apr 2013

    Posted 26 Apr 2013 Link to this post

    Thanks a lot, it work like a charm!
Back to Top