这份原稿.Micro 2.0和WP 8.1 -消息.附加而不是发送$eventArgs到事件处理程序

本文关键字:程序 事件处理 eventArgs 消息 Micro WP | 更新日期: 2023-09-27 18:15:49

我在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);
        }
    }

这份原稿.Micro 2.0和WP 8.1 -消息.附加而不是发送$eventArgs到事件处理程序

我在windows phone 8.1上开发了一个应用程序。当事件被触发时,不发送eventArgs。为什么?在旧的解决方案WP 8.0中,此语法可以正常工作....

I Found the solution…eventargs的类型是错误的,因为他指的是WP8的TextBox控件,即KeyEventArgs。WP 8.1中的文本框控件位于Windows.UI:XAML中。控件并使用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);
        }
    }