Fazer uma PerguntaFazer uma Pergunta
 

RespondidoExecuting Commands from *any* event

  • sexta-feira, 4 de agosto de 2006 13:37wpf michelle Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     

    I understand that commands can be triggered off certain events of certain controls.   For example, specifying  a Command for a Button will trigger it off the Click event.  But what if I wanted to trigger a command off of a different event -- like a Load event?  Is there a way to do this at all?  If so, can I do it from XAML only?

Respostas

Todas as Respostas

  • sexta-feira, 4 de agosto de 2006 18:11Brownie PointsMVP, ModeradorMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     

    Create a handler for the event and call RoutedCommand.Execute within your handler. I'm not sure if you should call CanExecute first or if Execute will check for you. (To err on the safe side call CanExecute first.)

    If you want this to be done strictly through XAML, you would need to derive a class from TriggerAction that fires a command and add it to an EventTrigger within XAML. If people think this utility would be useful, I could add it as a WorkItem for the WPF Toolbelt project.

  • sexta-feira, 4 de agosto de 2006 19:57lukemelia Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     
    If you want this to be done strictly through XAML, you would need to derive a class from TriggerAction that fires a command and add it to an EventTrigger within XAML. If people think this utility would be useful, I could add it as a WorkItem for the WPF Toolbelt project.

    I would find this useful...
  • segunda-feira, 7 de agosto de 2006 13:58wpf michelle Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     

    Yes, that would be a very useful utility.   Thanks Mike! 

  • segunda-feira, 7 de agosto de 2006 15:04Brownie PointsMVP, ModeradorMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     
    Done, the tool is scheduled for the WPF Toolbelt CTP 2 release scheduled for the end of August. If the class is available prior to the official release date (through a code commit) I will let you know here. If you'd like to follow the project, you can go here
  • quarta-feira, 9 de agosto de 2006 15:27wpf michelle Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     Respondido

    I looked into this further, and it doesn't seem that deriving from TriggerAction will work, since TriggerAction class is "public abstract" but it has 2 "internal abstract" methods [2 overloads for Invoke].  

    Any plans from MS to change this?   This could be really useful...

  • quarta-feira, 9 de agosto de 2006 18:30Brownie PointsMVP, ModeradorMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     
    Well that's not fair. And looking at the implementation of its derived classes, you can't override behavior with them either.
  • quarta-feira, 9 de agosto de 2006 18:46Brownie PointsMVP, ModeradorMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     
    I just logged a feature request on the feedback site. Go here to vote and add a comment. Hopefully this is something that can be added in time for the final version.
  • quinta-feira, 10 de agosto de 2006 14:42wpf michelle Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     
    I agree.  Thanks Mike!
  • quinta-feira, 17 de agosto de 2006 19:50Brownie PointsMVP, ModeradorMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     

    This is the feedback from Msft on the issue

     Microsoft wrote:
    This is by design for this version. We do understand that this is a valuable feature and are considering it for future versions.

    Thanks for the feedback!

    Looks like we won't get it with V1

  • segunda-feira, 6 de abril de 2009 21:45Brownie PointsMVP, ModeradorMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     Respondido

    Almost 3 years later we have a solution. The new blend behaviors api allows for custom trigger actions. I blogged about my ExecuteCommandAction here.


    Keep your head in the Clouds as you're coding .NET http://azurecoding.net