Caliburn.Micro 2.0和WP 8.1 - Message.Attach不会将$ eventArgs发送到事件处理程序

时间:2014-07-31 20:52:39

标签: c# xaml windows-phone-8.1 caliburn.micro eventargs

我在Windows Phone 8.1上开发了一个应用程序。触发事件时不会发送eventArgs。为什么?在旧的解决方案WP 8.0中,这种语法工作正常....

    <TextBox x:Name="Amount" Grid.Row="2" Grid.Column="1" InputScope="Number" Header="{Binding TbAmount}" micro:Message.Attach="[Event KeyUp] = [Action NumericKeyboard_OnKeyUp($source, $eventArgs)]"/>

这是事件处理程序:

    public void NumericKeyboard_OnKeyUp(object sender, KeyEventArgs e)
    {
        if (CultureInfo.CurrentCulture.ToString() != "en-US")
            return;

        if (e.VirtualKey == VirtualKey.None)
        {
            var distanceTb = sender as TextBox;
            distanceTb.Text = distanceTb.Text.Replace(",", ".");

            // reset cursor position to the end of the text (replacing the text will place
            // the cursor at the start)
            distanceTb.Select(distanceTb.Text.Length, 0);
        }
    }

1 个答案:

答案 0 :(得分:2)

  

我在Windows Phone 8.1上开发了一个应用程序。触发事件时不会发送eventArgs。为什么?在旧的解决方案WP 8.0中,这种语法工作正常....

我找到了解决方案...... eventargs的类型是错误的,因为他指的是WP8的TextBox控件,即KeyEventArgs。 WP 8.1中的TextBox控件位于Windows.UI:XAML.Controls中,并使用KeyRoutedEventArgs。

正确的代码是:

    public void NumericKeyboard_OnKeyUp(object sender, KeyRoutedEventArgs e)
    {
        if (CultureInfo.CurrentCulture.ToString() != "en-US")
            return;

        if (e.Key.ToString() == "188")
        {
            var distanceTb = sender as TextBox;
            distanceTb.Text = distanceTb.Text.Replace(",", ".");

            // reset cursor position to the end of the text (replacing the text will place
            // the cursor at the start)
            distanceTb.Select(distanceTb.Text.Length, 0);
        }
    }