質問

I've developed an app on windows phone 8.1. When the event is triggered is not sent the eventArgs. Why? In the old solution WP 8.0 this syntax works fine....

    <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)]"/>

This is the event handler:

    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);
        }
    }
役に立ちましたか?

解決

I've developed an app on windows phone 8.1. When the event is triggered is not sent the eventArgs. Why? In the old solution WP 8.0 this syntax works fine....

I Found the solution... the type of eventargs was wrong, because he was referring to the TextBox control of WP8 namely KeyEventArgs. The TextBox control in WP 8.1 is in the Windows.UI:XAML.Controls and use a KeyRoutedEventArgs.

The correct code is:

    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);
        }
    }
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top