1

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

1 回答 1

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);
        }
    }
于 2014-08-04T20:25:00.837 回答