ā Using mvvm toolkit- Why my view has no access to my command?
I got the following Code in the view model:
And the view:
I got a few button on the view, when it try to give the button a command to CalculateAndSave, method isn't available, is my binding wrong?
65 Replies
is just the designer saying its not available or did you try it during running app to check if the method is called?
if its just the designer.. well it isnt so smart..
you would have to tell it more explicitly of what type the datacontext is
Meaning what?
i tried just now running it
didnt hit the breakpoint of the command so it aint working for sure
ok
well since you didnt copy the part of the button i cant help further
Oh
@ACiDCA7
nothing to see much
just want to bind a command to it
click and command maybe clashing?
hmm
Nop. now when i click nothing happens
command isnt binded
Probably the entire view model isnt binded properly
no autocompletion on the method name
try setting datacontext in codebehind/where oyu are creating the window
I did
didnt help either
smth is quite odd here
try this
Should be called
CalculateAndSaveCommand
I have this code in place, it does nothing
like hengi said
Command
is missing in the binding name
dont change the methodname tho
just where you are binding
@ACiDCA7 , @hengi :
https://github.com/KostaKing/Calculator
GitHub
GitHub - KostaKing/Calculator
Contribute to KostaKing/Calculator development by creating an account on GitHub.
look at line 100 at the xaml
i got it
It doesnt work
the breakpoint isn't being activated in the command
The CalculatorVM needs to be partial so it can generate the code
And add it to the class
meaning?
whats next
still doesnt work
Try to run it and see if there are binding errors
Unless you set the design time type of the data context (don't remember exactly what it's called) it will not autocomplete and might give you a warning
Nothing shows up, btw you do have the full repo
the codebase is rly simple , just trying to convert it to using mvvm
u can run it on your own machine, press 1 and see nothing happens
it just doesnt go in the method
1 sec
grr i couldnt get it to work with the attribute aswell but if you go the "oldshool" way it works
but i dont wanna go oldschool lol
thats the point
why doesnt the attribute works?
like tf š
seems like the source generator doesn't work? need ilspy oof
im not on that lvl mate hah
btw can u give code?
yes it seems like .net 4.8 doesn't like the source generator of mvvm toolkit
thats interesting
any fix?
oh i didnt even check which target was set.. good point
yup am stuck on that 4.8
add this to calculator vm
Yup That works
but how do we make source generators work with 4.8?
why are you stuck on net framework? you should not go in with the mindset that new features get backported to old runtimes
legacy project mate
not my choice
ohhhh
millions of lines of code wont be switched to .net core overnight
you need to do right click on the calculator project and migrate to PackageReference
it's packages.config not working
hengi sorry
how do i migrate? what?
give more details mate š
in the solution explorer in visual studio, expand your Calculator project, right click "References" and select "Migrate packages.config to PackageReference"
also that, you need to set the LangVersion of the Project to at least 8..
net framework is stuck on 7.3
yup it is
it's not stuck, just edit the csproj
shit lol
i dont think srcgens are included in latest
but lemme try
open the csproj with editor and add
<LangVersion>9.0</LangVersion>
under "TargetFrameworkVersion"
works for me when migrated and the LangVersion manually addedhengi
after selecting refernces
where do i find migrate packages.config?
there's an article from Microsoft with screenshots: https://devblogs.microsoft.com/nuget/migrate-packages-config-to-package-reference/
The NuGet Blog
Migrate to PackageReference with 3 clicks - The NuGet Blog
Last year, we introduced the option to make PackageReference the default package management format for managing NuGet dependencies when installing the first NuGet package for a newly created projects. With Visual Studio Version 15.7 Preview 3, we have introduced the capability to migrate existing projects that use the packages.config format to u...
indeed it does work
sec doing it
to set the lang version: https://blog.ndepend.com/using-c9-record-and-init-property-in-your-net-framework-4-x-net-standard-and-net-core-projects/
you technically only need 8.0
i was under the impression that the MS sourcegens were jsut for net5+.. well TIL
soz am kinda lost lol
trying but
it's actually .NET Standard 2.0 I guess..
no Default package management format exsist
in the setting
The NuGet Blog
Migrate to PackageReference with 3 clicks - The NuGet Blog
Last year, we introduced the option to make PackageReference the default package management format for managing NuGet dependencies when installing the first NuGet package for a newly created projects. With Visual Studio Version 15.7 Preview 3, we have introduced the capability to migrate existing projects that use the packages.config format to u...
oh you only need to do the right click thing
you don't need to change the setting
hhaha
well i did
any chance 1 of you gives me an updated repo that works?
clearly above my head
I just need to update the lang ver u saying?
@AntiMatter you can either look at the branch or just merge, it's the new LangVersion and changing to ProjectReference
I merged
jesus lol thank you so much
i will go over what u did and learn from it
np lol, we also have a project at work with .net 4.8 because of WCF, we'll probably never drop that
it's good to know that source generators are indeed working
meeh i was just about to create a quick gif how to do it..xD
do it would love to save it š
i just merged i dont know tf going on lol
give me the fig
gif*
hope you like it..
ignore that its in german^^
amazing dude
thank you so much
you 2 my gods will sacrifice goat tonight @ACiDCA7 @hengi
š
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.