Hi,
You could translate from event handlers to commands using attached properties -
public class CalendarCommands
{
static public ICommand GetItemModifyingCommand(DependencyObject obj)
{
return (ICommand)obj.GetValue(ItemModifyingCommandProperty);
}
static public void SetItemModifyingCommand(DependencyObject obj, ICommand value)
{
obj.SetValue(ItemModifyingCommandProperty, value);
}
public static DependencyProperty ItemModifyingCommandProperty =
DependencyProperty.RegisterAttached(
"ItemModifyingCommand",
typeof (ICommand),
typeof (CalendarCommands),
new PropertyMetadata(CalendarChanged));
static void CalendarChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var calendar = (Calendar)d;
calendar.ItemModifying += (s, args) =>
{
var cmd = GetItemModifyingCommand(d);
if (cmd != null)
cmd.Execute(args);
};
}
}
and then bind the attached command to a command property of your window or view-model -
<planner:Calendar Name="calendar"
local:CalendarCommands.ItemModifyingCommand=
"{Binding MyCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:Window1}}"
then the parameter specified will be the respective event-args object -
public class MyCommand : ICommand
{
public void Execute(object parameter)
{
var args = (ItemModifyConfirmEventArgs)parameter;
Debug.WriteLine(args.Item.HeaderText);
}
...
}
Regards,
Slavcho
Mindfusion