57 Replies
I'm so confused of why is it not working hhh
So this is an error in the XAML editor/designer. You need to be skeptical of those as they're less reliably true than ones coming from C#.
Ok ❤️
post full xaml
Sure
Ensure you've tried to build and run the app. If that causes an exception, then it's a real error. If it doesn't actually build, then check the Output window for details.
It is building
But the buttons won't work
are you doing anything in codebehind
Let me screen that for you
also if you're using MVVM Toolkit I'd just use
[RelayCommand]
and make a method, to be honest.Thats what I did ^^
In my app.xaml :
<Application x:Class="WpfApp1.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApp1"
xmlns:viewModel="clr-namespace:WpfApp1.MVVM.ViewModel"
xmlns:view="clr-namespace:WpfApp1.MVVM.View"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="./Theme/MenuButtonTheme.xaml" />
<ResourceDictionary Source="./Theme/TextboxTheme.xaml"/>
</ResourceDictionary.MergedDictionaries>
<DataTemplate DataType="{x:Type viewModel:HomeViewModel}">
<view:HomeView></view:HomeView>
</DataTemplate>
<DataTemplate DataType="{x:Type viewModel:AsteroidsViewModel}">
<view:AsteroidsView></view:AsteroidsView>
</DataTemplate>
</ResourceDictionary>
</Application.Resources>
</Application>
that's not what you've posted
I'm loading my models
Uh
Thats how i load it
I still need the code behind for the main window
Ok
It is this one:
no, that's your view model. I'm asking for the code behind of the main window.
MainWindow.xaml.cs
Sorry
ok, you either deleted the cs file or you're not reading my message properly
MainWindow.xaml.cs
not MainWindow.xaml
using System.Windows;
namespace WpfApp1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void TextBox_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e)
{
}
}
}
thanks
It didnt show up in my file explorer sorry
so.... what's not working exactly?
seems like it should be working.
Sure, the command binding is not working
But it is building successfully
Without changing too much, I would write your
MainViewModel
like the following (this won't fix your problem though)
define "not working", are you getting an error?
It is showing me this error "Object reference not set to an instance of objet
"
Thanks, I will use it ^^
What does your app do at runtime? Is the button disabled? Is it enabled and does nothing when you click it?
ok, that's the designer, but does it actually run and execute the command?
No it doesn't
Ensure you've set a breakpoint in the method/command when testing.
Oops
sorry I didn't tell you
It doesn't even build sorry

I'm getting this error
I would rewrite it the relay commands as per Klarth's suggestion earlier
Is this a custom 
RelayCommand
when you're already using Mvvm Toolkit? 
it will fix your problem, because the way you initialised the relay command makes it expect a command parameter
Ok I'll try ^^
(also it's just convenient to make MVVM toolkit do it)

wait...
you're.... not using MVVM Toolkit?
I am

Why do you have
ObservableObject
and RelayCommand
defined? Use the Mvvm Toolkit's versions.ok i think there's confusion here
MVVM Toolkit is a Microsoft supported MVVM Framework
I mean no I don't but I created my own ... 😂

Yes, you're doing MVVM, but MVVM Toolkit is a separate library
with all of this stuff built in
... and also 

Ok 😂
I mean I'm beginning in C#
CommunityToolkit.Mvvm 8.1.0
This package includes a .NET MVVM library with helpers such as:
- ObservableObject: a base class for objects implementing the INotifyPropertyChanged interface.
- ObservableRecipient: a base class for observable objects with support for the IMessenger service.
- ObservableValidator: a base class for objects implementing the INot...
install this and delete your own
Ok and how do I add the library globaly in the project ?
FYI, this only applies if you're using the Mvvm Toolkit library.
Just import it in the mainwindow ?
walk before running
install via nuget into the WPF project.
Ok then thanks, I will inform you if it is actually good ^^ ! ❤️
Thanks a lot
Umm yes using the library is much simpler
Love y'all
Thanks @Klarth ❤️
And you too @superpat64