2016-03-28 52 views
-3

这是迄今为止我添加到我的cs文件的唯一代码。我收到以下错误。Win10通用应用程序不能从键盘输入

类型或命名空间名称“的形式命名空间中不存在‘System.Windows’

类型或命名空间名称‘KeyEventArgs’找不到

名称‘关键’呢在目前情况下

using System.Windows.Forms; 

private void OnKeyDownHandler(object sender, KeyEventArgs e) 
{ 
    if (e.Key == Key.Return) 
    { 
     textBlock1.Text = "You Entered: " + textBox1.Text; 
    } 
} 

这被复制,并从他们的网站上粘贴不存在。它出什么问题了?

+2

请保持干净。 – gunr2171

+0

你在你的项目中包括了什么dll? – gunr2171

+0

对不起书呆子怒气。我没有使用任何DLL。这是假定在本地系统库中的代码。 –

回答

0

乔希,添加到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 & Syste m.Windows.Forms

即按OK

https://imgur.com/a/8taGr

看看这个链接,照片后,(在画面底部开始)

+0

我正在制作通用Windows 10应用程序或UWP应用程序(我认为这就是它的名字)... –

+0

您是否知道如何添加引用?如果你这样做,添加一个引用System.Windows.Controls.Ribbon – CTR12

+0

@JoshuaBlevins你是团结还是你在Visual Studio的方式?为什么这些意思stackoverflowers downvote你的问题......这是好的 – CTR12

1

正如@Raymond小陈说,你的代码”被复制的是WPF application。一般来说,当我们谈论“Windows 10通用应用程序”时,我们的意思是UWP app。它们不一样。

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

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

要开发一个应用程序UWP,请参阅Get started with Windows appsHow-to guides for UWP apps on Windows 10

相关问题