Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Binding Appointment ItemModifying event (and sending the appointment as CommandParameter) (Read 1948 times)
gilav
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 5
Joined: May 12th, 2018
Binding Appointment ItemModifying event (and sending the appointment as CommandParameter)
May 15th, 2018 at 3:10pm
Print Post  
I binded the event to a command successfully, but when using CommandParameter="{Binding}" , I get the whole DataContext of the view on the command function and not the appointment I changed.

how can I send the changed appointment to the CommandParameter?

Im breaking my head over this.

Thank you in advance ! Smiley

EDIT:
I send the Element of the whole Calendar, and extracted the ItemSelection from that.

I would wish if it would send it correctly with normal binding, but that works too
  
Back to top
 
IP Logged
 
Slavcho
God Member
*****
Offline


tech.support

Posts: 3152
Joined: Oct 19th, 2005
Re: Binding Appointment ItemModifying event (and sending the appointment as CommandParameter)
Reply #1 - May 16th, 2018 at 7:10am
Print Post  
Hi,

You could translate from event handlers to commands using attached properties -

Code
Select All
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 -

Code
Select All
<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 -

Code
Select All
public class MyCommand : ICommand
{
	public void Execute(object parameter)
	{
		var args = (ItemModifyConfirmEventArgs)parameter;
		Debug.WriteLine(args.Item.HeaderText);
	}
	...
} 



Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint