Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > Avalon

ICommand woes...

Closed Thread
 
Thread Tools Display Modes
Old 06-26-2007   #1 (permalink)
Lloyd Dupont
Guest


 

ICommand woes...

I tried to create a SetColor command and a ColorPicker which uses it.

There is one effect I cannot reproduce, it is tracking the CommandSource and
wether it's valid.

By that I mean if I create a MenuItem like that:

<MenuItem Header="Blue" Command="{x:Static local:MyCommands.SetColor}"
CommandParameter="{x:Static Colors.Blue}" />

It enables/disables depending on wether the currently focused element
respond to the SetColor command.


But my ColorPicker never get any CanExecute or whatever event call,
therefore I cannot update it appropriately (i.e. enable/disable) when the
focused element change.

I implemented ICommandSource, used a RoutedEvent, I never get any relevant
info....

Any idea what I could have missed?!?

Old 06-27-2007   #2 (permalink)
Lloyd Dupont
Guest


 

Re: ICommand woes...

found it!

it's quite tricky, I remember read about it in a blog 6 month ago but it's
nowhere in the documentation!!!

RoutedCommand.CanExecuteChanged strore the event handlers as WeakReference.
Therefore you have to hold a reference to the handlers your self if you want
your event handler to be called....

Old 06-27-2007   #3 (permalink)
Radek Cerny
Guest


 

Re: ICommand woes...

Well done!

I am playing in the same area and am sure to have come across this soon.

Thanks.

"Lloyd Dupont" <net.galador@ld> wrote in message
news:eX9XTzHuHHA.1672@TK2MSFTNGP06.phx.gbl...
> found it!
>
> it's quite tricky, I remember read about it in a blog 6 month ago but it's
> nowhere in the documentation!!!
>
> RoutedCommand.CanExecuteChanged strore the event handlers as
> WeakReference.
> Therefore you have to hold a reference to the handlers your self if you
> want
> your event handler to be called....
>



Old 06-27-2007   #4 (permalink)
Lloyd Dupont
Guest


 

Re: ICommand woes...

Thanks!! :-D

Additional tip:

I was trying to get a value from the command source:
I.e. I have a color picker, I want it to be initialized to the current color
of the SetColorCommand target.
There is no way to do that!

But... little trick....
ICommand.CanExecute(object obj) take any object as argument.

I used something like:
public class CommandCanExecuteArg
{
object val;
public CommandCanExecuteArg(object val)
{
this.val = val;
}
public object Parameter { get { return val; } }
public object ReturnValue { get; set; }
}


and I pass an instance of it to CanExecute(), this way the
SetColorCommandTarget can return its current color in ReturnValue

--
Regards,
Lloyd Dupont
NovaMind Software
Mind Mapping at its best
www.nova-mind.com

"Radek Cerny" <radekcerny@nospam.optusnet.com.au> wrote in message
news:O8ZpNDRuHHA.3368@TK2MSFTNGP02.phx.gbl...
> Well done!
>
> I am playing in the same area and am sure to have come across this soon.
>
> Thanks.
>
> "Lloyd Dupont" <net.galador@ld> wrote in message
> news:eX9XTzHuHHA.1672@TK2MSFTNGP06.phx.gbl...
>> found it!
>>
>> it's quite tricky, I remember read about it in a blog 6 month ago but
>> it's
>> nowhere in the documentation!!!
>>
>> RoutedCommand.CanExecuteChanged strore the event handlers as
>> WeakReference.
>> Therefore you have to hold a reference to the handlers your self if you
>> want
>> your event handler to be called....
>>

>
>


Closed Thread

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Bootmgr woes henrikwl Vista installation & setup 6 02-22-2007 03:54 PM
OEM Woes David Veeneman Vista General 2 02-19-2007 12:21 AM
Ownership Woes Falor Vista installation & setup 1 02-16-2007 11:53 AM
IIS 7 Woes aelliott Vista General 4 12-15-2006 10:17 AM
Icommand mailkerry@gmail.com Avalon 0 11-15-2006 02:23 AM








Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50