Пример #1
0
        private void SetupCustomMessageBindings()
        {
            DocumentContext.Init();
            MessageBinder.SpecialValues.Add("$orignalsourcecontext", context =>
            {
                var args = context.EventArgs as RoutedEventArgs;
                if (args == null)
                {
                    return(null);
                }

                var fe = args.OriginalSource as FrameworkElement;
                if (fe == null)
                {
                    return(null);
                }

                return(fe.DataContext);
            });

            MessageBinder.SpecialValues.Add("$mousepoint", ctx =>
            {
                var e = ctx.EventArgs as MouseEventArgs;
                if (e == null)
                {
                    return(null);
                }

                return(e.GetPosition(ctx.Source));
            });
        }
Пример #2
0
        private void SetupCustomMessageBindings()
        {
            DocumentContext.Init();
            MessageBinder.SpecialValues.Add("$orignalsourcecontext", context =>
            {
                var args = context.EventArgs as RoutedEventArgs;
                if (args == null)
                {
                    return(null);
                }

                var fe = args.OriginalSource as FrameworkElement;
                if (fe == null)
                {
                    return(null);
                }

                return(fe.DataContext);
            });


            MessageBinder.SpecialValues.Add("$mousepoint", ctx =>
            {
                var e = ctx.EventArgs as MouseEventArgs;
                if (e == null)
                {
                    return(null);
                }

                return(e.GetPosition(ctx.Source));
            });

            MessageBinder.SpecialValues.Add("$pressedkey", (context) =>
            {
                // NOTE: IMPORTANT - you MUST add the dictionary key as lowercase as CM
                // does a ToLower on the param string you add in the action message, in fact ideally
                // all your param messages should be lowercase just in case. I don't really like this
                // behaviour but that's how it is!
                var keyArgs = context.EventArgs as KeyEventArgs;

                if (keyArgs != null)
                {
                    return(keyArgs.Key);
                }
                return(null);
            });

            MessageBinder.SpecialValues.Add("$pressedmodifierkey", (context) =>
            {
                var keyArgs = context.EventArgs as KeyEventArgs;

                if (keyArgs != null)
                {
                    return(keyArgs.KeyboardDevice.Modifiers);
                }
                return(null);
            });
        }