Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is causing "The type or namespace name 'UI' does not exist in the namespace" error?

Tags:

c#

xaml

uwp

I am working on a UWP application and I am trying to do something with the values of a SelectedItem in a GridView. So as I usually do with WPF I went into the XAML and Typed my event name in the XAML and let VS create the event in code for me.

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

and the VS created event looks like this

    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();
    }

Right away I get a red squiggly line under the UI in the Windows.UI.Xaml.Controls part. There is a using at the top of the page to include that and VS wouldn't let add any other UWP references.

I can get the error to go away as I have in other parts of the application by changing the ItemClickEventArgs to RoutedEvenArgs but in this case I really need the ClickedItem as an argument to be passed to the code behind.

I have just talked to someone else getting started with UWP and they said they are having the same issue on other cLick events. So are we both doing something wrong or is there something missing from our application that is needed for the UI to be recognized?

The full error I am getting is this: Error CS0234 The type or namespace name 'UI' does not exist in the namespace 'app name' (are you missing an assembly reference?)

like image 883
Buck Hicks Avatar asked Dec 13 '25 06:12

Buck Hicks


1 Answers

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

That means you have a namespace in your app that contains Windows.

Either change your namespace, or prefix the UWP one:

global::Windows.UI.Xaml.Controls

See also How to: Use the Global Namespace Alias (C# Programming Guide).

like image 102
CodeCaster Avatar answered Dec 15 '25 19:12

CodeCaster



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!