WPF Data Binding Shows Blank
I would like to have an
AppState
class within my WPF apps that can hold common properties I may want to access throughout the application, such as the assembly’s version number.
When I tried to create an instance of this class within my Main Window and then access one of the instance’s properties via a data binding, it’s just showing blank.
I know the property itself is set since I can set the window title via code behind to this property, so I’m a bit stumped why nothing populates when I try to access the instance via a binding. Can anyone shed some light on what I may be missing? See attached for a skeleton example.7 Replies
Have you considered using di for wpf?
All properties that are used for binding must be public
Is there a good example of that somewhere online? Still new to dependency injection, so not 100% sure what it would look like for WPF.
That fixed it, thank you!!! I knew it was something simple, just wasn’t sure what I was missing.
Also you might want to consider creating a viewmodel instead of setting datacontext to the view itself
I’m dealing with an existing application which I didn’t write that already heavily uses code-behind, so I’m just leaving things as-is for now, since it’s working fine currently. On the first application I create myself from scratch I’ll definitely look into using MVVM, though.
https://github.com/devdevdeveau/wpf ignore the asp.net stuff, it was a sample for something else
Another Example https://github.com/SirRufo/so-77657479-PageNavigation based on the nuget package https://www.nuget.org/packages/Wpf.Extensions.Hosting
GitHub
GitHub - SirRufo/so-77657479-PageNavigation: Example for stackoverflow
Example for stackoverflow. Contribute to SirRufo/so-77657479-PageNavigation development by creating an account on GitHub.
Wpf.Extensions.Hosting 1.1.2
Package Description