2
votes

What I want to achieve is just to inherit UWP App class not from Windows.UI.Xaml.Application class, but from some base class, inherited from the "standard" one.

However, when I do it:

namespace MyNamespace
{
    sealed partial class App : MyUwpBaseApplication
    {
        public App()
        {
            this.InitializeComponent();
        }
    }
}

and xaml:

<local:MyUwpBaseApplication
    x:Class="MyNamespace.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:MyNamespace">

</local:MyUwpBaseApplication>

I receive both: the design time error in XAML designer as well as compilation error:

Error XDG0008 The name "MyUwpBaseApplication" does not exist in the namespace "using:MyNamespace". MyNamespace App.xaml 1

I need the base class to use MvvmCross and Xamarin.Forms. But the error I receive is generic, not related to any of those.

Visual Studio: 15.7. Windows: 10 Fall Creators Update.

How can I handle that?

2

2 Answers

5
votes

The things become quite weird when you get to UWP development, especially considering that this is Windows Native platform development (hello Microsoft!)

But Visual Studio is really very "capricious" with XAML in general and UWP in particular.

I still don't know exact reason what you should do with the project to make this work, but the solution is definitely somewhere among of these hints.

It's definitely has something with:

  • running Visual Studio as Administrator
  • removing bin, obj folders
  • cleaning the solution
  • rebuilding the project

At least, after all those operations done, the project now compiles quite well (and always, independently on whether bin, obj exists or not). So, I am considering, that that might be something with some caching of the built binaries somewhere else (apart from the project folder).

One of possible reasons was having several UWP projects at a time in one solution (at least, error messages when I was building one of the projects was appearing on all of them), so I had to hide others when building aimed one.

(And there still should be xmlns:local="using:MyNamespace", not clr-namespace (otherwise there is some other error to appear)).

-1
votes

This is actually just an error in your XAML syntax, not a problem with inheritance.

You need to use "clr-namespace" instead of "using" in the xaml namespace declaration. clr-namespace tells the parser that what follows is the actual name of the namespace. If it doesn't recognize a prefix (and "using" is not a recognized prefix) the parser assumes the value of your xmlns:local attribute refers to a namespace mapping called "using:MyNamespace", which obviously does not exist.

So, declare the namespace in your XAML like this:

xmlns:local="clr-namespace:MyNamespace"

and you'll be good to go.