Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 732
kasra Avatar asked Sep 12 '25 19:09

kasra


2 Answers

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"
like image 196
Jammer Avatar answered Sep 15 '25 14:09

Jammer


Thanks to Jammer.

I had to set the UserControl to:

<UserControl xmlns="https://github.com/avaloniaui"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:views="clr-namespac/e:ToDoList.Views"
             mc:Ignorable="d" d:DesignWidth="250" d:DesignHeight="450"
             x:Class="ToDoList.Views.ToDoListView">

    Suca dio cane
</UserControl>
like image 20
largehadroncollider Avatar answered Sep 15 '25 15:09

largehadroncollider