2011-05-26 1 views

Répondre

4
<i:Interaction.Triggers> 
     <i:EventTrigger EventName="SizeChanged"> 
      <ei:CallMethodAction MethodName="WndSizeChanged" 
       TargetObject="{Binding}" /> 
     </i:EventTrigger> 
    </i:Interaction.Triggers> 

méthode WndSizeChanged devrait être public et avoir la même signature que l'événement delegte il vous abonnant à.

1

une façon confortable pour créer des comportements est d'utiliser l'approche DelegateCommand comme dans Prism:

Lire ici: Prism behavior

+0

Cela ne répond pas vraiment à la question, car la commande délégué ne reçoit pas les arguments d'événement. – McGarnagle

+0

vous pouvez utiliser Generate DelegateCommands avec les arguments d'événement en tant que paramètre – fixagon

1

Caliburn Micro a quelques belles façons de le faire.

De la documentation:

<Button Content="Remove" 
     cal:Message.Attach="Remove($dataContext)" /> 

$eventArgs – Passes the Trigger’s EventArgs or input parameter to your Action. Note: This will be null for guard methods since the trigger hasn’t actually occurred. 
$dataContext – Passes the DataContext of the element that the ActionMessage is attached to. This is very useful in Master/Detail scenarios where the ActionMessage may bubble to a parent VM but needs to carry with it the child instance to be acted upon. 
$source – The actual FrameworkElement that triggered the ActionMessage to be sent. 
$view - The view (usually a UserControl or Window) that is bound to the ViewModel. 
$executionContext - The actions's execution context, which contains all the above information and more. This is useful in advanced scenarios. 
$this - The actual ui element to which the action is attached. 
Questions connexes