C#C
C#4y ago
cap5lut

❔ AvaloniaUI InvalidCastException

I started playing around with AvaloniaUI and I get a InvalidCastExceptions.
the MainWindow's XAML:
<Window 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:main="clr-namespace:cap5lut.net.Growbox.Client.Views.Main"
        xmlns:controls="clr-namespace:cap5lut.net.Growbox.Client.Controls"
        mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
        x:Class="cap5lut.net.Growbox.Client.Views.Main.MainWindow"
        x:DataType="main:MainWindowViewModel"
        x:CompileBindings="True"
        Title="{Binding Title}">
    <controls:ServerAddForm
        DataContext="{Binding ServerAddForm}"/>
</Window>
the MainWindowViewModel:
public class MainWindowViewModel : Model
{   
    private string _title;
    private ServerAddFormModel _serverAddForm;

    public MainWindowViewModel()
    {
        _title = $"Servers - Growbox - v{Assembly.GetExecutingAssembly().GetName().Version} - cap5lut.net";
        _serverAddForm = new ServerAddFormModel();
    }
    
    public string Title
    {
        get => _title;
        set => SetField(ref _title, value);
    }

    public ServerAddFormModel ServerAddForm
    {
        get => _serverAddForm;
        set => SetField(ref _serverAddForm, value);
    }
}
(Model is just an INotifyPropertyChanged implementation)
Was this page helpful?