You could do the following

<Button Command={Binding MyCommendInTheController, Source={StaticResource
controller}/>

Also, you could use the CallMethodAction and completely forget about the use
of Commands. I think Actions are way more flexible than commands. If you
have to use Commands, you could use the InvokeCommandAction if you need to
use a different trigger.

As a side note, I would avoid communication between the view and the
controller. All my view has to know about is the ViewModel.

Miguel

On Sat, Jul 24, 2010 at 2:22 PM, Winston Pang <[email protected]> wrote:

> I'm assuming your controller is bound to the control's datacontext? If so,
> I normally expose properties that return the ICommand, and basically the
> concrete implementation is a DelegateCommand (
> http://msdn.microsoft.com/en-us/library/ff650631.aspx).
>
> That's pretty much it.
>
> On Sat, Jul 24, 2010 at 11:25 AM, Greg Keogh <[email protected]> wrote:
>
>>  Folks, I’ve been searching for the correct way for a WPF control command
>> (button click, list selection, etc) to run a method in the controller. I’m
>> not using any official framework at the moment, I’m just experimenting with
>> the raw techniques of ridding the control of code (as is the trend in MVVM
>> these days). My controller class is defined like this in the XAML:
>>
>>
>>
>> <ctls:BaseWpfControl.Resources>
>>
>>        <ctls:FooController x:Key="controller"/>
>>
>> </ctls:BaseWpfControl.Resources>
>>
>>
>>
>> Note that I’m quite happy with the way my properties of the controller are
>> bound to control properties in the classic way, so I have no problem with
>> the controller-to-control direction. It’s the reverse that has me stumped.
>> How can I get a control event to run a method in the controller?
>>
>>
>>
>> Web searches are voluminous and contradictory. Most recommend frameworks
>> but various helper classes are available and some use attached properties.
>> Can someone cut through all the noise for me and point me to the recommended
>> way of doing this?
>>
>>
>>
>> I currently have code like this in the control and I want to get rid of
>> it:
>>
>>
>>
>> controller = (NavigatorController)Resources["controller"];
>>
>> :
>>
>> // in button click event
>>
>> controller.DoThing();
>>
>>
>>
>> Cheers,
>>
>> Greg
>>
>> _______________________________________________
>> ozwpf mailing list
>> [email protected]
>> http://prdlxvm0001.codify.net/mailman/listinfo/ozwpf
>>
>>
>
> _______________________________________________
> ozwpf mailing list
> [email protected]
> http://prdlxvm0001.codify.net/mailman/listinfo/ozwpf
>
>


-- 
Miguel A. Madero Reyes
www.miguelmadero.com (blog)
[email protected]
_______________________________________________
ozwpf mailing list
[email protected]
http://prdlxvm0001.codify.net/mailman/listinfo/ozwpf

Reply via email to