3

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?)

1
  • Yes. The folder that the file is located in is called Windows. Is that my issue? Commented Jan 10, 2016 at 21:46

2 Answers 2

6

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).

Sign up to request clarification or add additional context in comments.

Comments

1

One of bugs I can see is that your handler should be marked async, also you should use await operator when you call async method:

private async 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);
        await messageDialog2.ShowAsync();
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.