© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•4y ago•
6 replies
cap5lut

❔ AvaloniaUI InvalidCastException

I started playing around with AvaloniaUI and I get a
InvalidCastException
InvalidCastException
s.
the
MainWindow
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>
<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
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);
    }
}
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
Model
is just an
INotifyPropertyChanged
INotifyPropertyChanged
implementation)
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

✅ Responsive ScrollViewer AvaloniaUI
C#CC# / help
12mo ago
✅ Boolean values in AvaloniaUI
C#CC# / help
6d ago
✅ Problem with binding (#AvaloniaUI)
C#CC# / help
12mo ago
How to start with AvaloniaUI
C#CC# / help
2w ago