Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Passing Sender and EventArguments with DelegateCommand

$
0
0

Hello,

I have a method OnClose which gets called on press of ShortCut key and i want the same method to get called on Close of Window from the Window X button. Below has been done for implementing ShortCut key:

<CommandBinding Command="cbase:UIShortCutsHelper.AltCCommand" Executed="OnClose"></CommandBinding>

and in code-behind, OnClose method has been written as below:

private void OnClose(object sender, ExecutedRoutedEventArgs e)
{
}

Now i want to call the same method using DelegateCommand on close of Window. Below is what I am doing in xaml at UserControl  level:

<Interact:Interaction.Triggers><Interact:EventTrigger EventName="Closed"><cbase:ExecuteCommandAction Command="{Binding OnCloseWindowCommand}" CommandParameter="{Binding RelativeSource={RelativeSource Self}, Path=EventArgument}" /></Interact:EventTrigger></Interact:Interaction.Triggers>

In Code-behind I have declared an ICommand property as below:

 public ICommand OnCloseWindowCommand { get; set; }

and now i want to intialize the above command in Constructor:

//Need to pass the object and ExecutedRoutedEventArgs below
OnCloseWindowCommand = new DelegateCommand(OnClose());

How can i pass the object and eventargs in above command?

Thanks,

Abdi


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>