Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The first MVVM example has some problems #59

Open
cbaugher opened this issue Sep 3, 2023 · 7 comments
Open

The first MVVM example has some problems #59

cbaugher opened this issue Sep 3, 2023 · 7 comments
Labels
bug Something isn't working

Comments

@cbaugher
Copy link

cbaugher commented Sep 3, 2023

In step 3 it says to:

"Add the following code to the MainWindowViewlModel class in MainWindowViewModel.cs."

I think that should be MainViewModel class in MainViewModel.cs. There is no MainWindowViewModel class or .cs file.

In step 4:
x:DataType="vm:MainWindowViewModel"

should be:
x:DataType="vm:MainViewModel"

Also, there needs to be:
xmlns:views="clr-namespace:BasicMvvmSample.Views"

somewhere before the Title line.

MainWindowViewModel is used in a few other places as well. Changing it to MainViewModel makes all the compile errors go away.

Unfortunately I'm now getting an error that says "A project with an Output Type of Class Library cannot be started directly." I understand what it's saying but I don't know how to fix it.

@cbaugher cbaugher added the bug Something isn't working label Sep 3, 2023
@cbaugher
Copy link
Author

cbaugher commented Sep 3, 2023

I got it to work even though there are still two errors. I had to set the startup project as "BasicMvvmSample.Desktop" (which I don't really understand), and then tell it to continue debugging even though there were errors.

This is really confusing. Lol

@timunie
Copy link
Collaborator

timunie commented Sep 3, 2023

The issue here is that we have different templates in different IDEs now. I personally use Rider, which produces the files you see in the sample. Back when I wrote them, this was the same for VS. Now we have TemplateStudio which does it different. The idea is to have one project where you define the App and one or several projects for the OS you want to target. In your case desktop only, but Android could be added easily.

Will think about how to reflect it best in the samples and then update it. Thanks for sharing your feedback 🤗

@archfrog
Copy link

archfrog commented Oct 28, 2024

Thanks for the info on how to continue with this sample. I had one weird issue, though:

  1. The InitializeComponent() call in MainWindow.axaml.cs did not compile, so I had to comment it out. I then built and ran the project, which produced a black window (I use Windows Dark Mode) with no controls. I then re-enabled the InitializeComponent() call, built, and ran the project again. This time, the window was populated with controls as shown in the sample documentation. I can't explain what happened here, but perhaps it is due to new linking methods or something.

I was then able to run the sample on Windows 11 using Rider. This is probably just me doing something wrong, though.

@archfrog
Copy link

One more thing (I am completely new to GUI development in general)... I had to change Debug.WriteLine("Click!"); into System.Console.WriteLine("Click!"); to get any output in the output window when using Rider. I don't know why, just thought you might want to know.

@timunie
Copy link
Collaborator

timunie commented Oct 31, 2024

@archfrog Debug.WriteLine("Click!"); is only visible if you actually debug the app and move to debug console. This is something you have to configure in Rider itself.

@archfrog
Copy link

@timunie Thanks, is there any reason at all to use Debug.WriteLine() over Console.WriteLine() when the latter is much more user-friendly and works without user intervention? I believe the WriteLine() statement is removed in one of the exercises or it makes a lot of sense to do so there.

@timunie
Copy link
Collaborator

timunie commented Oct 31, 2024

I tend to use this to get more debug info during development, but I don't want it for production. That is what this is made for. More: https://stackoverflow.com/questions/3012822/whats-the-difference-between-console-writeline-vs-debug-writeline

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants