Multyble key for message.attach

Topics: Actions & Coroutines
Aug 25, 2011 at 10:41 AM

Im trying to implement a simple zoom function for a textblock, this is a prof of concept that will be extendet later but im unsure about my implementation. What i would like to know if this is the propper way of using CM's message.attach along with handling the event. On my textblock i attached the event as shown.

cc:Message.Attach=

"[Event PreviewKeyDown ] = [Action FontSizeChange()];"

 

 from my viewmodel.

        public void FontSizeChange()
        {
            if (Keyboard.IsKeyDown(Key.LeftCtrl) )
            {
                if (Keyboard.IsKeyDown(Key.Up))
                {
                    FontSize++;
                    NotifyOfPropertyChange(() => FontSize);
                    NotifyOfPropertyChange(() => ArlBody);
                }
                else if (Keyboard.IsKeyDown(Key.Down))
                {
                    FontSize--;
                    NotifyOfPropertyChange(() => FontSize);
                    NotifyOfPropertyChange(() => ArlBody);
                }
                
            }
        }

 My question goes to, is there a better way to make use of the message.attach property for using multiblekey, or is my implementation as good or bad as any other. one of my concerns is that im gonna fire my action every time someone presses a key(hint: textblock), or is this just a hassel i have to live with, sins i guess i have to check what keys a pressed somehow.

Any help is appriciated, im new at using caliburn, and i got thrown into a large HMI projekt that uses CM, as a part of my intership, so im learning as i go along atm. 

Aug 25, 2011 at 10:44 AM

I suppose that this discussion could be interesting to you.

Aug 25, 2011 at 11:19 AM

Thx blade, i did look at your replay in mentioned discussion, but it seem to me like a more generic way to solve this problem, and as it is right now i only need ctrl+ up and down so it seemed abit overkill to try your solution. That said its defenetly something im gonna try play with on the side.

Aug 25, 2011 at 2:28 PM

My approach is about multi-key binding, but note that cshepherd's solution is just a better way to leverage keyboard input without without being forced to handle the Keyboard object directly.

In my opinion it is the way to go, since you could just add two different methods to increase and decrease the font, moreover it just needs the KeyTrigger class and an extension over the parser wich is quite trivial (instead of parsing the key directly, use a KeyGestureConverter to get both the key and the modifier). :)