【问题标题】:Caliburn.Micro 2.0 and WP 8.1 - Message.Attach not send $eventArgs to event handlerCaliburn.Micro 2.0 和 WP 8.1 - Message.Attach 不发送 $eventArgs 到事件处理程序
【发布时间】:2014-09-23 23:29:01
【问题描述】:

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

【问题讨论】:

  • 您是否尝试过删除 x:Name 属性?
  • @mvermef: 也删除 x: Name 不起作用...

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


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多