질문하기질문하기
 

답변됨Executing Commands from *any* event

  • 2006년 8월 4일 금요일 오후 1:37wpf michelle 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     

    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?

답변

모든 응답

  • 2006년 8월 4일 금요일 오후 6:11Brownie PointsMVP, 중재자사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     

    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.

  • 2006년 8월 4일 금요일 오후 7:57lukemelia 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    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...
  • 2006년 8월 7일 월요일 오후 1:58wpf michelle 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     

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

  • 2006년 8월 7일 월요일 오후 3:04Brownie PointsMVP, 중재자사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    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
  • 2006년 8월 9일 수요일 오후 3:27wpf michelle 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     답변됨

    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...

  • 2006년 8월 9일 수요일 오후 6:30Brownie PointsMVP, 중재자사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    Well that's not fair. And looking at the implementation of its derived classes, you can't override behavior with them either.
  • 2006년 8월 9일 수요일 오후 6:46Brownie PointsMVP, 중재자사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    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.
  • 2006년 8월 10일 목요일 오후 2:42wpf michelle 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    I agree.  Thanks Mike!
  • 2006년 8월 17일 목요일 오후 7:50Brownie PointsMVP, 중재자사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     

    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

  • 2009년 4월 6일 월요일 오후 9:45Brownie PointsMVP, 중재자사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     답변됨

    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