First reference some assemblies:
- System.Windows.Interactivity
- GalaSoft.MvvmLight.Extras.WPF4
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" xmlns:cmd="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.WPF4"Within you window component, add the event to command handler's
<i:Interaction.Triggers> <i:EventTrigger EventName="Loaded"> <cmd:EventToCommand Command="{Binding Mode=OneWay, Path=LoadedCommand}" PassEventArgsToCommand="True" /> </i:EventTrigger> <i:EventTrigger EventName="Closing"> <cmd:EventToCommand Command="{Binding Mode=OneWay, Path=ClosingCommand}" PassEventArgsToCommand="True" /> </i:EventTrigger> </i:Interaction.Triggers>Then some code to process the command:
private RelayCommand<RoutedEventArgs> loadedCmd; public RelayCommand<RoutedEventArgs> LoadedCommand { get { return this.loadedCmd ?? (this.loadedCmd = new RelayCommand<RoutedEventArgs> ((rea) => { // Use event argument 'rea' if you need it // (but PassEventArgsToCommand="True" is needed in the Xaml, see above) this.ActivityText = "Copy files from \'" + m_AsyncPhotoBackup.TargetDirectory + "\' to \'" + m_AsyncPhotoBackup.DestinationDirectory + "\'."; m_AsyncPhotoBackup.RunWorkerAsync(); })); } }
No comments:
Post a Comment