gpt4 book ai didi

c# - 是什么导致 "The type or namespace name ' UI' does not exist in the namespace"错误?

转载 作者:行者123 更新时间:2023-11-30 20:21:06 30 4
gpt4 key购买 nike

我正在开发一个 UWP 应用程序,我正在尝试对 GridView 中的 SelectedItem 的值执行一些操作。因此,就像我通常使用 WPF 所做的那样,我进入 XAML 并在 XAML 中键入我的事件名称,然后让 VS 在代码中为我创建事件。

<GridView x:Name="DataGrid1"
ItemClick="dg_ItemClick">
<!-- Just -->
<!-- Some -->
<!-- Normal -->
<!-- XAML -->
</GridView>

VS 创建的事件看起来像这样

    private void dg_ItemClick(object sender, Windows.UI.Xaml.Controls.ItemClickEventArgs e)
{
Biz.Customer cust = e.ClickedItem as Biz.Customer;
var messageDialog2 = new MessageDialog(cust.Code, cust.Company);
messageDialog2.ShowAsync();
}

我立即在 Windows.UI.Xaml.Controls 部分的 UI 下看到一条红色波浪线。页面顶部有一个 using 来包含它,VS 不允许添加任何其他 UWP 引用。

我可以通过将 ItemClickEventArgs 更改为 RoutedEvenArgs 来消除错误,就像我在应用程序的其他部分所做的那样,但在这种情况下,我确实需要将 ClickedItem 作为参数传递给后面的代码。

我刚刚和其他人谈过开始使用 UWP,他们说他们在其他点击事件中遇到了同样的问题。那么,我们是否都做错了什么,或者我们的应用程序是否缺少识别 UI 所需的某些东西?

我得到的完整错误是这样的:错误 CS0234 namespace “应用程序名称”中不存在类型或 namespace 名称“UI”(是否缺少程序集引用?)

最佳答案

The type or namespace name 'UI' does not exist in the namespace 'app name'

这意味着您的应用程序中有一个包含 Windows 的命名空间。

要么更改您的命名空间,要么为 UWP 添加前缀:

global::Windows.UI.Xaml.Controls

另见 How to: Use the Global Namespace Alias (C# Programming Guide) .

关于c# - 是什么导致 "The type or namespace name ' UI' does not exist in the namespace"错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34711110/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com