How can I use the internal access modifier on my views in Avalonia? The application will run but the xaml preview says invalid markup. x:ClassModifer="internal"
doesn't seem to work or exist.
<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:vm="clr-namespace:MyApp.ViewModels"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="MyApp.Views.MainView">
<StackPanel VerticalAlignment="Center" HorizontalAlignment="Center">
<TextBlock Text="{Binding Greeting}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</StackPanel>
</UserControl>
internal partial class MainView : ReactiveUserControl<MainViewModel> {
public MainView() {
InitializeComponent();
this.WhenActivated(disposables => { });
AvaloniaXamlLoader.Load(this);
}
}
internal class MainViewModel : ReactiveObject, IRoutableViewModel {
public IScreen HostScreen { get; }
public string Greeting => "Welcome to Avalonia!";
public string UrlPathSegment { get; } = Guid.NewGuid().ToString().Substring(0, 5);
public MainViewModel(IScreen screen) {
HostScreen = screen;
}
}
This occurs in Avalonia because the previewer is being run by the platform specific assembly (such as AvaloniaApplication.Desktop). If you mark a view as internal, the platform application assembly no longer has access to it. Unfortuately there are few ways to work around this. Even InternalsVisibleTo doesn't affect it.
Your options are to
In option 2, the previewer seems to always use debug even if your IDE is configured for Release. I know neither of these are really ideal, but that's all I have found to make it work.