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

Command Alternative for DatePicker

3 Answers 106 Views
DatePicker
This is a migrated thread and some comments may be shown as answers.
Scott
Top achievements
Rank 1
Scott asked on 29 Apr 2015, 09:46 PM
I'm using a datepicker in my silverlight application.  The SelectedDate is bound to a property in my ViewModel (I'm using MVVM).  I noticed there is no command for DatePicker.  The DatePicker is used to select a start date to view a schedule.  I have a method in my ViewModel that refreshes the user's schedule, and when a new date is picked I want the schedule to refresh with the newly selected date.  I would prefer a command, but I am trying to use SelectionChanged since there's no command availabled.  I call this RefreshSchedule method in the SelectionChanged event, but the problem is this is firing every time SelectionChanged is fired, including when the data is initially bound.  Is there any way I can only call this method when a USER changes the selection, not just any time the bound data is loaded/changed?  I feel like I'm missing something obvious here.

3 Answers, 1 is accepted

Sort by
0
Kalin
Telerik team
answered on 04 May 2015, 07:55 AM
Hello Scott,

You can use EventToCommandBehavior in order to execute a custom command in the ViewModel whenever the SelectionChanged event has occurred. Check the following code snippet:

<telerik:RadDatePicker SelectedValue="{Binding SelectedDate}">
    <telerik:EventToCommandBehavior.EventBindings>
        <telerik:EventBinding Command="{Binding CustomCommand}"
                        EventName="SelectionChanged"
                        PassEventArgsToCommand="True" />
    </telerik:EventToCommandBehavior.EventBindings>
</telerik:RadDatePicker>

I tested it and the command was not executed with the initial set of SelectedValue, so this should help you to achieve the required.

Hope this will work for you.

Regards,
Kalin
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
0
Scott
Top achievements
Rank 1
answered on 04 May 2015, 05:49 PM
I tried using EventToCommandBehavior as described in your post, but unlike your results the command is being fired on the setting of SelectedValue for me.  I have code that populates SelectedValue, and when that binding occurs the command is being fired (I dont want it to).  This causes an unnecessary refreshing of my user's schedules.  I still need to be able to discern between code updating the value and the user clicking on the calendar and selecting a value.  I only want to call this update method when the user selected a new date.
0
Kalin
Telerik team
answered on 07 May 2015, 09:04 AM
Hello Scott,

Please check the attached sample project and let me know how it works for you. What I can also suggest you would be to implement a property (flag) that indicates whether your are updating the SelectedValue, so you can skip calling the ScheduleView update method.

Hope this helps.

Regards,
Kalin
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
Tags
DatePicker
Asked by
Scott
Top achievements
Rank 1
Answers by
Kalin
Telerik team
Scott
Top achievements
Rank 1
Share this question
or