VisualStudio confuses Avalonia XAML files with WPF XAML
See original GitHub issueUpdate:
Workaround - use .axaml
file extension instead of .xaml
.
I created a custom Window
this way:
namespace MyProject.Desktop.Views
{
public abstract class BaseWindow : Window
{
public BaseWindow()
{
this.InitializeComponent();
#if DEBUG
this.AttachDevTools();
#endif
}
protected void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}
[...]
}
}
Now I use it in my views:
(MainWindow.xaml)
<base:BaseWindow
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:base="clr-namespace:MyProject.Desktop.Views"
mc:Ignorable="d"
x:Class="MyProject.Desktop.Views.Main.MainWindow"
Icon="/Assets/icon_square.png"
Title="MyProject">
<StackPanel>[...]</StackPanel>
</base:BaseWindow>
In MainWindow.xaml.cs, the view is declared as
namespace SparkEvo.Desktop.Views.Main
{
public partial class MainWindow : BaseWindow
[...]
At this point, the XAML designer in Visual Studio 2017 gets full of errors…
It does not recognize the tags anymore (“The type XXXX was not found. Verify that you are not missing an assembly reference.”). But…
- If I make MainWindow a simple Window, so that it does not extend BaseWindow, the error disappears.
- I can compile even with this error, but the XAML designer is unusable, example there is no autocomplete and working gets really difficult.
Avalonia version: 0.8.0 Target Frameworks: netcoreapp2.2;net461
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:11 (6 by maintainers)
Top Results From Across the Web
Avalonia XAML
These pages will introduce you to how XAML is used specifically in Avalonia UI. For background information about how XAML is used elsewhere...
Read more >WinForms, WPF, Avalonia or something else? : r/csharp
Avalonia is similar enough that you can always pick it up later if you want. Start with learning XAML and just using event...
Read more >Porting WPF to AvaloniaUI - jammer
A write up of developer experience in porting a large complex WPF application to cross-platform AvaloniaUI and .NET 6.
Read more >I can't use blend for visual studio 2022 to edit axaml
Hello, I'm studying Avalonia UI to migrate my wpf app. so, I created Avalonia mvvm project and open it in blend for VS...
Read more >The call is ambiguous between the following methods
I had this issue when copying my XAML between controls. I just had to change my x:Class="mynamespace" where mynamespace is the proper ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
#111 contains a workaround for this issue. It doesn’t fix the underlying issue but at least allows you to open a XAML file with the Avalonia editor from the “Open With…” menu. Thanks @donandren for coming up with this.
@stevenbrix yeah, the problem is this:
So it’s showing the WPF designer instead of ours because
base:BaseWindow
is in theclr-namespace:MyProject.Desktop.Views
and not in the avalonia namespace.IMO it should be looking at the
xmlns="https://github.com/avaloniaui"
namespace to decide which designer to show, not the namespace of the root element.@waliarubal we originally did that, but that caused other problems IIRC (I can’t remember the details right now). Also they’re XAML files, we shouldn’t have to come up with our own extension 😉 This is 100% a bug in VS that should be fixed IMO.