1.    26 Jun 2007 #1
    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?!?

      My System SpecsSystem Spec

  2.    27 Jun 2007 #2
    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....

      My System SpecsSystem Spec

  3.    27 Jun 2007 #3
    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....
    >



      My System SpecsSystem Spec

  4.    27 Jun 2007 #4
    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....
    >>

    >
    >


      My System SpecsSystem Spec


Similar Threads
Thread Forum
Video Woes
I installed virtual pc 207 to run a dedicated game server (halo) and was told that the video card was not able to support the game. is there soem...
Virtual PC
AT&T DSL woes...
I am/was a Bellsouth DSL (1.5 Mbit) customers and ever since the merge or buyout from AT&T, I have been noticing my speed dropping at night, well,...
Network & Sharing
DLL Woes
Hi All, Adobe reader 9 won't open and is complaining of a missing vdk150a.dll How do I fix this? Have uninstalled and re-installed Reader but to...
Drivers
More vista woes
Ok so after 2 months of fighting with vista just to do my work I decided to try Windows Movie Maker. Got ... this far , a dialog box with the text...
Vista General
OEM Woes
I just got a Lenovo laptop with vista installed. First bummer: No Windows Vista CD. Okay, that's par for the course these days. But not even a...
Vista General
IIS 7 Woes
Prior to installing Vista, I was running IIS 6 on WinXP Pro. I have a web app that I built and runs locally. It's vanilla ASP with a Microsoft...
Vista General
Icommand
>From the Expressions interactive designer there is a Csharp example which I have put thru a VB converter - I am stuck on the following (last)...
Avalon

Our Sites
  • Ten Forums
  • Eight Forums
  • Seven Forums
  • PC Help Forum
  • Help Me Bake
  • Site Links
  • Contact Us
  • Privacy and Cookies
  • About Us
    Windows Vista Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

    Designer Media Ltd
    All times are GMT -5. The time now is 11:28.
    .