How to use EventToCommandBehavior in WPF Scheduler (Calendar)
In the WPF SfScheduler, you can use the command for the events such as EditorOpening, EditorClosing, and ViewChanged.
C#
Add the commands for EditorOpening, EditorClosing, and ViewChanged with its event args in the ViewModel
public class SchedulerViewModel : NotificationObject
{
private ICommand editorOpeningCommand;
private ICommand editorClosingCommand;
private ICommand viewChangedCommand;
public ICommand EditorOpeningCommand
{
get { return editorOpeningCommand; }
}
public ICommand ViewChangedCommand
{
get { return viewChangedCommand; }
}
public ICommand EditorClosingCommand
{
get { return editorClosingCommand; }
}
public ICommand ContextMenuOpeningCommand
{
get { return contextmenuOpeningCommand; }
}
public void editorOpening(AppointmentEditorOpeningEventArgs arg)
{
MessageBox.Show("Editor Opened");
}
public SchedulerViewModel()
{
editorOpeningCommand = new DelegateCommand<AppointmentEditorOpeningEventArgs>(editorOpening);
editorClosingCommand = new DelegateCommand<AppointmentEditorClosingEventArgs>(EditorClosing);
contextmenuOpeningCommand = new DelegateCommand<SchedulerContextMenuOpeningEventArgs>(ContextmenuOpening);
viewChangedCommand = new DelegateCommand<ViewChangedEventArgs>(ViewChanged);
}
public void ViewChanged(ViewChangedEventArgs arg)
{
var oldValue = arg.OldValue;
var newValue = arg.NewValue;
if(oldValue != null)
MessageBox.Show("View changed");
}
public void EditorClosing(AppointmentEditorClosingEventArgs arg)
{
MessageBox.Show("Editor closed");
}
public void ContextmenuOpening(SchedulerContextMenuOpeningEventArgs arg)
{
MessageBox.Show("Context Menu opened");
}
}
XAML
Bind the corresponding ViewModel commands to the Scheduler.
<Window.DataContext>
<local:SchedulerViewModel/>
</Window.DataContext>
<Grid>
<scheduler:SfScheduler x:Name="scheduler"
ViewType="Week"
local:AppointmentEditorOpeningCommandWithEventArgs.Command="{Binding EditorOpeningCommand}"
local:AppointmentEditorClosingCommandWithEventArgs.Command="{Binding EditorClosingCommand}"
local:VisibleDatesChangingCommandWithEventArgs.Command="{Binding ViewChangedCommand}">
</scheduler:SfScheduler>
</Grid>
|
