Passing parameter to MessageAction

Topics: Actions & Coroutines
May 6, 2011 at 2:33 PM

Hi All,

I've got this example situation:

 <i:Interaction.Triggers>
                <i:EventTrigger EventName="StrokeCollected">
                    <cm:ActionMessage MethodName="StrokeCollected" >
                        <cm:Parameter Value="$eventArgs.Stroke"></cm:Parameter>
                    </cm:ActionMessage>
                </i:EventTrigger>
            </i:Interaction.Triggers>

I'm routing the event StrokeColelcted on the InkCanvas to an ActionMessage. If I pass the $eventArgs it works perfectly, but if I try to pass a property on the event args it does.
Question is: should it work, or it is not working by design ? If it is by design, shuldn't be better to have this possibility ?
Thanks a lot !
Felix
Coordinator
May 6, 2011 at 2:39 PM

The ability to "dot" through parameters is not supported in Micro. Here's a discussion that details how to author a plugin that will enable that: http://caliburnmicro.codeplex.com/discussions/242508

May 6, 2011 at 2:42 PM

@Rob: what if I write a receipe about this and submit it to you? Could it be useful in your opinion, or it is better to keep this capability un-related to the CM documentation?

May 6, 2011 at 4:58 PM

@Rob and @BladeWise thank you. I'm interested in the BladeWise recipe too :)

May 9, 2011 at 9:44 PM

BTW, my used strategy: http://www.felicepollano.com/2011/05/09/DottedSyntaxInMessageParameterWithCaliburnMicro.aspx

May 9, 2011 at 10:07 PM

Nice approach. :) Have you considered using a temporary DependencyObject with an object DependencyProperty, to one-time data-bound the (eventual) sub-property of the special value? Instead of using reflection directly I prefer to use this approach to retrieve property values, if possible. This way you would avoid recursion and manual property navigation, leaving this stuff to the Binding engine itself.

May 9, 2011 at 10:13 PM

@BladeWise, yep I think the solution you propose is probably better in a WPF sense, mine is probably simpler. Yep manual navigation and reflection is not so fancy, but the result is very few code. If you have that recipes somewhere, please post, I'm courious on your approach.

See you,

Felix

May 9, 2011 at 10:18 PM

I was just writing down a simple example :)

public class Dummy : DependencyObject
{
        public static readonly Dummy Instance = new Dummy();

        public static DependencyProperty ValueProperty = DependencyProperty.Register(typeof(Dummy), typeof(object), new UIPropertyMetadata(null));
}

public object GetPropertyValue(object source, string propertyPath)
{
         var binding = new Binding () { Source = source, Path = propertyPath, Mode = BindingMode.OneTime };
         BindingOperations.SetBinding(Dummy.Instance, Dummy.ValueProperty, binding;
         return Dummy.Instance.GetValue(Dummy.ValueProperty);
}