Basic layout (VB.NET & WPF/XBAP):
I have a MainPage – mainpage.xaml
Inside the MainPage I have a frame that hosts other pages. The first page that is auto loaded is the LogIn – LogIn.xaml
The user enters their email to login (no password required, just email to identify, its an internal app so passwords are not required or even wanted by users).
On MainPage.xaml the header should have a “Hello ” TexBlock (name: ui_txbUserName). The LogIn page has a method which on submit gets the UserID (for other reasons and saves it) and the User Name.
I want to change the ui_txbUserName when the person logs in and update if he/she logs out of one account into another. I have looked at INotifyPropertyChanged and Dependency Properties and im just not sure how to go about doing this! Any help would be awesome!!!
Thanks!
UsingOfficerID – its a global variable set when a person logs in, its used all over the place in the application.
I have tried the Following inside the sample app:
http://www.2shared.com/file/68enzucg/SampleApp.html
None of this is reflected in the UI
Ok, I thought I’d add another answer which addresses the specifics of your sample application. I’ve had a look through the sample, but the code seems to be a bit in a state of flux! Firstly, you haven’t set the DataContext of MainWindow (the view) anywhere, this should be set to an instance of your view model (UserViewModel.vb, although I would consider renaming either the view or the view model so that they are e.g. MainView and MainViewModel).
You can set the DataContext in several ways, using a view first or view model first approach. One quick way to start testing is in the constructor of your view:
Now, in your UserViewModel, you have a UserName property, but it seems to return and set a User object username property. Even though the user object never seems to be set anywhere. To keep things simple, I just used a string instead with a new backing field:
Originally, you had called MyBase.OnPropertyChanged(“Address”) for some reason?? Maybe this was a copy/paste error, but the string value must match the name of the property whose value has changed, as the binding engine will use reflection to retrieve the new property value.
Finally, I just changed the binding expression in MainWindow.xaml
Because the DataContext isn’t explicitly set on the TextBlock, it will use the DataContext of the view (UserControl) which is set to an instance of UserViewModel. This means that it will bind to a UserName property on that DataContext which is what you want. To test it, you can set the value of Me.UserName = “Something” in the constructor of the UserViewModel.
Hopefully you can see how the binding works for strings, and you can work out where you need to go to get it working for your User type.