Home > OS >  "Unable to resolve type" when referencing a xaml file through namespaces
"Unable to resolve type" when referencing a xaml file through namespaces

Time:09-10

I'm trying to build the example project that is provided in the Avalonia website but I'm having difficulty with certain parts.

I want to use a xaml element in a xaml window in another file like so:

<Window xmlns="https://github.com/avaloniaui"
        xmlns:local="using:Buguette.Views">
<Panel>
        <local:MusicStoreView />
</Panel>

</Window>

But I'm getting an error saying "Unable to resolve type MusicStoreView from namespace using:Buguette.Views". (MusicStoreView is the name of the file I'm trying to include here).

However everything works fine when I just copy the contents of the MusicStoreView file to where <local:MusicStoreView /> is supposed to be.

I followed the steps in the website but I'm still getting this error.

Any help would be much appreciated.

CodePudding user response:

You need to use clr-namespace:

<Window xmlns="https://github.com/avaloniaui"
        xmlns:local="clr-namespace:Buguette.Views">
<Panel>
        <local:MusicStoreView />
</Panel>

</Window>

Sometimes you also need to provide the assembly name, such as:

xmlns:viewModels="clr-namespace:MyApp.Core.ViewModels;assembly=Myapp.Core"
  • Related