WPF local: when using Dependency Injection
Hello,
My WPF app is utilizing dependency injection following https://achraf-chennan.medium.com/net-core-dependency-injection-for-wpf-core-62dc282690f8 (which removes StartupUri from the App.xaml file).
When I'm attemping to utilize data binding, but local:SessionConverter isn't being recognize and I'm not understanding how to work around it as I'm unable to set the DataContext in the main window due to the parameters.
The .xaml code looks like the following (button data removed)
Could anyone point me in the right direction here?
9 Replies
Don't keep the data in the Window but prefer to use MVVM, especially if you're using design patterns already.
You rarely ever need a direct reference to the window
I plan on having the user make a data selection on the MainWindow which allows me to later direct the program based on that input. I would need the direct reference in this situation no?
Have you used bindings before?
I have not which is probably why I should stop trying to run before crawl. I'm repurposing an old VB program and WPF looked like a great design upgrade as the prior file is just an exe that runs based on the current window. I'm attempting to make the user select their functionality instead of reading the active window
In my earlier attempts before reseraching MVVM I was taking the result of the Radio Button selection and parsing the string in order to set a variable, but it appears Data Binding is the best practice for that
Oh. Yeah. The structure of WPF generally aims towards using MVVM. However you can use it like winforms, etc. But that'll make expanding the project a pain. Especially if it's a larger project
That's where I ended up as well. It's probably not "needed" but because of the UI customization that WPF allows I wanted to dive into that instead of Winforms - however it seems like winforms would have probably been the better choice here
Although from what I'm seeing here - while it violates MVVM - I would be able to have my features work if I just didn't use bindings and violated that architecture
Although I don't plan on having to greatly expand the project once it's complete
It's really good to aim for MVVM / XAML because modern frameworks do use XAML and it's fairly easy if you use MVVM to port it in the future since the data doesn't rely on the framework itself
I see. So de-coupling the data selection from MainWindow will ensure I can safely do that then?
It should, yes.