Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Win10通用应用程序无法从键盘获取输入_C#_.net_Uwp_Windows 10 Universal - Fatal编程技术网

C# Win10通用应用程序无法从键盘获取输入

C# Win10通用应用程序无法从键盘获取输入,c#,.net,uwp,windows-10-universal,C#,.net,Uwp,Windows 10 Universal,这是迄今为止我添加到cs文件中的唯一代码。我得到以下错误 命名空间“System.Windows”中不存在类型或命名空间名称“forms” 找不到类型或命名空间名称“KeyEventArgs” 当前上下文中不存在名称“Key” 这是从他们的网站复制和粘贴的。有什么问题吗?Josh,添加对dll System.Windows.Controls.Ribbon的引用 还添加对dll System.Windows.Forms的引用 在顶部添加以下内容: using System; using Syste

这是迄今为止我添加到cs文件中的唯一代码。我得到以下错误

命名空间“System.Windows”中不存在类型或命名空间名称“forms”

找不到类型或命名空间名称“KeyEventArgs”

当前上下文中不存在名称“Key”


这是从他们的网站复制和粘贴的。有什么问题吗?

Josh,添加对dll System.Windows.Controls.Ribbon的引用 还添加对dll System.Windows.Forms的引用

在顶部添加以下内容:

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
它应该会起作用

如何添加引用:

右键单击引用

单击添加引用

你应该得到那一页

在System.Windows中搜索

选中以下项:System.Windows.Controls.Ribbon和System.Windows.Forms

然后按ok


请查看此链接中的图片,图片从底部开始

正如@Raymond Chen所说,您复制的代码是用于。一般来说,当我们谈论Windows10通用应用程序时,我们的意思是。而且它们不一样

要在UWP中实现相同的功能,可以使用以下代码:

private void OnKeyDownHandler(object sender, KeyRoutedEventArgs e)
{
    if (e.Key == Windows.System.VirtualKey.Enter)
    {
        textBlock1.Text = "You Entered: " + textBox1.Text;
    }
}

要开发UWP应用程序,请参阅和。

请保持它的整洁。您的项目中包含了哪些dll?很抱歉有点书呆子的愤怒。我没有使用任何dll。这是本机系统库中的代码。如果您正在制作通用应用程序,则使用System.Windows.Forms的可能性很低。您正在从WPF文档复制代码。WPF和UWP不一样。我正在制作一个通用的Windows 10应用程序或UWP应用程序,我想这就是它的名称…你知道如何添加引用吗?如果是,请添加对System.Windows.Controls的引用。Ribbon@JoshuaBlevins顺便问一下,您是在unity中还是在Visual Studio中?为什么这意味着stackoverflowers否决了你的问题。。。这是一个很好的VisualStudio。我只是在上面说,当我在Unity中制作视频游戏时,这是没有必要的。我如何添加参考资料,为什么我要使用该库作为参考资料?@JoshuaBlevins你需要参考资料,因为人们通常不会做你想做的事情。无论如何,下面是如何添加引用。我将编辑我的答案,并张贴我该做什么的图片。
private void OnKeyDownHandler(object sender, KeyRoutedEventArgs e)
{
    if (e.Key == Windows.System.VirtualKey.Enter)
    {
        textBlock1.Text = "You Entered: " + textBox1.Text;
    }
}