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

Custom commands

1 Answer 128 Views
ScheduleView
This is a migrated thread and some comments may be shown as answers.
Brandon
Top achievements
Rank 1
Brandon asked on 12 Oct 2015, 01:58 PM

I've created a new command in my ViewModel of the scheduleview that works properly in a context menu associated with the scheduleview, however when I try and place this command on a button outside the scheduleview control it doesn't trigger that an appointment has been selected or not. 

I can make the CanExecute always return true and then it will fire the event properly when clicked, however I need it to disable/enable when an appointment is selected and it has specific values set in the appointment.  The edit button triggers the selection changed ok when outside the schedule view.  How do I get this same functionality for my command/button?

public DelegateCommand StartVisitCommand { get { return this.startVisitCommand; } set { this.startVisitCommand = value; } }

<telerik:RadButton Content="Start Visit" Grid.Column="4"
 Command="{Binding DataContext.StartVisitCommand, ElementName=scheduleview}" CommandTarget="{Binding ElementName=scheduleview}"
CommandParameter="{Binding SelectedAppointments, ElementName=scheduleview}"
DockPanel.Dock="Right"
 />

private void StartVisitCommandExecuted(object parameter)
{
    IEnumerable appointments = parameter as IEnumerable;
    SqlAppointment appt = appointments.OfType<SqlAppointment>().Where(x => x.TimeMarkerID == 3).FirstOrDefault();
 
    SchedulingInterface.CreateDocumentationByAppt(appt);
}
 
 
private static bool CanExecuteStartVisitCommand(object parameter)
{
    IEnumerable appointments = parameter as IEnumerable;
    if (appointments != null)
    {
        SqlAppointment appt = appointments.OfType<SqlAppointment>().Where(x => x.TimeMarkerID == 3).FirstOrDefault();
        if (appt != null)
            return appt.CurrentTimeMarkerId == "3";
    }
    return false;
}

1 Answer, 1 is accepted

Sort by
0
Accepted
Kalin
Telerik team
answered on 13 Oct 2015, 09:00 AM
Hi Brandon,

You would need to invalidate the command in appropriate moment, in order to retrigger the CanExecute method. This can be done for example in the AppointmentSelectionChanged event handler as shown below:

private void scheduleView_AppointmentSelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{
    (this.DataContext as ViewModel).StartVisitCommand.InvalidateCanExecute();
}

Hope this helps.

Regards,
Kalin
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
ScheduleView
Asked by
Brandon
Top achievements
Rank 1
Answers by
Kalin
Telerik team
Share this question
or