Using MessageBinder.SpecialValues in Windows 8 app not working?
Asked Answered
B

1

2

I'm brand new to Caliburn.Micro, so I'm hoping somebody might be able to help me here :).

I'm trying to use MessageBinder.SpecialValues in my Windows 8 app, but I can't get it to work. I'm adding a new "$pointerPercentage" to know the percentage (float between 0.0 and 1.0) of how far the mouse is positioned within an element (for a music keyboard in my synthesizer app). Everything else is currently working (so I believe I have Caliburn.Micro wired up properly).

I've added the following to the Configure method of my App.xaml.cs:

protected override void Configure()
{
    container = new WinRTContainer();
    container.RegisterWinRTServices();

    MessageBinder.SpecialValues.Add("$pointerPercentage", ctx =>
    {
        return 1.0f;
    });
}

Then I'm using it from a PointerMoved event within a Canvas element:

<Canvas x:Name="keyCanvas" Background="#338B8BDC"
    cal:Message.Attach="[Event PointerMoved] = [Action UpdateKeyboard($pointerPercentage)]" />

The UpdateKeyboard method in my ViewModel does get fired (I break into it with a debugger), but the parameter passed in is always 0.0f (not 1.0f as set in the SpecialValues code above).

What am I doing wrong? Any help would be appreciated :).

Base answered 5/12, 2012 at 21:21 Comment(1)
Did you try sticking a breakpoint on the anonymous method in Configure? I've not used SpecialValues myself but what about the dollar, I know CM uses the dollar sign to signify a special value but does it need it when configuring one? Let me have a look at CM source...Kishakishinev
K
4

I found your issue: Problem lies in CM source on this line:

else if (MessageBinder.SpecialValues.ContainsKey(parameterText.ToLower()) || char.IsNumber(parameterText[0]))

Not sure if it's considered a problem with the source - CM treats all SpecialValues keys as-is, but converts any specified action message special parameter strings to lowercase before comparing to the keys in the SpecialValues dictionary

The solution is to just add your SpecialValues parameter key as lowercase!

protected override void Configure()
{
    container = new WinRTContainer();
    container.RegisterWinRTServices();

    MessageBinder.SpecialValues.Add("$pointerpercentage", ctx =>
    {
        return 1.0f;
    });
}

I've seen you've posted this on CM codeplex site too, I've answered there - in my opinion this should be done on both the key in the dict and the key in your action message params to prevent this from happening. (It could be done when the SpecialValues.Add method is called to minimise code impact) - but that's something for CM devs to look at

Kishakishinev answered 6/12, 2012 at 11:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.