Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The typical way to do this in WPF is by using the Model-View-ViewModel pattern. Read more about it <a href="http://blogs.msdn.com/b/johngossman/archive/2005/10/08/478683.aspx" rel="nofollow">here</a></p> <p>Basically you have to create a class (the ViewModel) that will notify your button (the View) that it must change its contents when UserLoggedIn (the Model) changes. This class must implement the <code>INotifyPropertyChanged</code> and trigger the PropertyChanged event when the value of UserLoggedIn changes thus the UI changes accordingly. So you should almost never reference your button (btnLogin) from code, instead, the button should be data bound to a variable in your ViewModel object from XAML and get notified when it changes.</p> <p>The beauty of using this pattern is that you will be using a declarative approach for most of the logic, using data binding and triggers and that the UI logic will be separate from your business logic. If you're new to WPF I suggest you read about the MVVM pattern first as it will save you <strong>a lot</strong> of time in the long run.</p> <p>The logic you show there performs exactly the same task a trigger would perform but you're probably mixing business code with UI code (i.e. you have a class that manages both the login <strong>and</strong> knows about which picture to show when the user is logged in).</p> <p>However, if you want to stick with your design. I'm guessing the problem is that your only running that code once ("I have this piece of code when the Window is Loaded"), and you should run CheckLoginButton when the user logs in, or more precisely, when the UserLoggedIn value changes to true or false.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload