在Windows 8应用中使用MessageBinder.SpecialValues无法正常工作? [英] Using MessageBinder.SpecialValues in Windows 8 app not working?

查看:36
本文介绍了在Windows 8应用中使用MessageBinder.SpecialValues无法正常工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Caliburn.Micro的新手,所以希望有人可以在这里为我提供帮助:)。



我正在尝试在Windows 8应用中使用MessageBinder.SpecialValues,但无法正常工作。我要添加一个新的 $ pointerPercentage,以了解鼠标在某个元素内(对于我的合成器应用中的音乐键盘而言)定位的距离百分比(介于0.0和1.0之间)。其他所有内容目前都在工作(因此,我相信Caliburn.Micro可以正确连接)。



我已将以下内容添加到App.xaml的Configure方法中。 cs:

 受保护的覆盖无效Configure()
{
container = new WinRTContainer();
container.RegisterWinRTServices();

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

然后我在Canvas元素内的PointerMoved事件中使用它:

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

我的ViewModel中的UpdateKeyboard方法确实被触发了(我用调试器闯入了它),但是传入的参数始终为0.0f(而不是上面的SpecialValues代码中设置的1.0f)。



我在做什么错?任何帮助将不胜感激:)。

解决方案

我发现了您的问题:问题出在此行的CM源中:

 否则,如果(MessageBinder.SpecialValues.ContainsKey(parameterText.ToLower())|| char.IsNumber(parameterText [0]))

不确定是否被认为是源问题-CM会处理所有 SpecialValues 键保持原样,但是在与 SpecialValues 字典

$ b $中的键进行比较之前,将所有指定的操作消息特殊参数字符串转换为小写。 b

解决方案是将您的 SpecialValues 参数键添加为小写!

 受保护的重写void Configure()
{
container = new WinRTContainer();
container.RegisterWinRTServices();

MessageBinder.SpecialValues.Add( $ pointerpercentage,ctx =>
{
return 1.0f;
});我已经看到您也将此内容发布在CM Codeplex网站上我已经回答了这个问题-我认为应该同时使用dict的键和操作消息参数中的键来防止这种情况的发生。 (可以在调用SpecialValues.Add方法以最大程度地减少代码影响时完成)-但这是CM开发人员应注意的事情


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 :).

解决方案

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

这篇关于在Windows 8应用中使用MessageBinder.SpecialValues无法正常工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆