You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The problem with constructor injection in WPF is that usercontrol hierachy and how one would normally write XAML, wont use the serviceprovider to fetch usercontrols.
Vehicles are generated on the fly by the XAML binding and wont be requested from the ServiceProvider.
Usually controls are spawned from the UI rather than from the codebehind...
I am struggling to pass the viewmodel to the view as a parameter constructor, while still being able to design my UI in xaml.
I randomly came across this discussion, is there any possibility that you found an elegant solution?
I am struggling to pass the viewmodel to the view as a parameter constructor, while still being able to design my UI in xaml. I randomly came across this discussion, is there any possibility that you found an elegant solution?
If your viewmodel only exists once: use Singleton and simply reference it in your usercontrol
if your viewmodel exists pr usercontrol / window, instantiate a new one and pass it to the constructor or instantiate it in the constructor .... or do everything like MVC and let the codebehind be the Viewmodel ... usually the easiest option.
ViewModels only make sense if they aggregate several UserControls
Hi again (sorry for the long delay)
The problem with constructor injection in WPF is that usercontrol hierachy and how one would normally write XAML, wont use the serviceprovider to fetch usercontrols.
eg
Vehicles are generated on the fly by the XAML binding and wont be requested from the ServiceProvider.
Usually controls are spawned from the UI rather than from the codebehind...
So i dont know how useful DI is for WPF...