I'm working in VS2022 with Avalonia for the first time, the app contains a basic layout that consists of a SplitView control, with a ListBox in the Pane that acts as a sidebar, when items are selected the relevent UserControl should appear in the content side of the SplitView.
I think the below code should work however in the designer and also when I run the app, I see that instead of the UserControl, I see "Not Found: NewApp.Views.HomePageView". This is odd as its located and named correctly, the app was also created from the MVVM Template and contains the ViewLocator file.
Can anyone help me understand where I'm going wrong please?
The MainWindow.axaml looks like this;
<StackPanel>
<SplitView IsPaneOpen="{Binding IsPagePaneOpen}"
OpenPaneLength="150"
CompactPaneLength="50"
DisplayMode="CompactInline"
<SplitView.Pane>
<StackPanel>
<ListBox>
<ListBoxItem>A</ListBoxItem>
<ListBoxItem>B</ListBoxItem>
</ListBox>
<Button Command="{Binding TriggerPagePaneCommand}">
-
</Button>
</StackPanel>
</SplitView.Pane>
<SplitView.Content>
<Border>
<TransitioningContentControl Content="{Binding CurrentPage}"/>
</Border>
</SplitView.Content>
</SplitView>
</StackPanel>
The MainWindowViewModel looks like;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using System.Drawing.Printing;
namespace NewApp.ViewModels
{
public partial class MainWindowViewModel : ViewModelBase
{
[ObservableProperty]
private bool _isPagePaneOpen = false;
[ObservableProperty]
private ViewModelBase _currentPage = new HomePageViewModel();
[RelayCommand]
private void TriggerPagePane()
{
IsPagePaneOpen = !IsPagePaneOpen;
}
}
}
The UserControl View (HomePageView.axaml) code contians only the base text in all new files, while the ViewModel (HomePageViewModel.cs) is empty, shown below;
namespace NewApp.ViewModels
{
internal class HomePageViewModel : ViewModelBase
{
}
For completeness sake, the HomePageView.axaml code;
<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"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="NewApp.HomePageView"
xmlns:vm="using:NewApp.ViewModels">
Welcome to Avalonia!
</UserControl>