I have a Button
which needs to be enabled/disabled programmatically. I want to achieve this using a binding to a bool
. Here is the Button XAML:
<Button x:Name="logInButton" Height="30" IsEnabled="{Binding IsLoggedIn}">
<Image Source="/images/img.png"></Image>
</Button>
Here is the code being called:
public MainWindow()
{
InitializeComponent();
enabled = false;
}
private bool enabled;
public bool IsLoggedIn
{
get
{
return enabled;
}
set
{
enabled = value;
}
}
The value of the property IsLoggedIn
is assigned correctly. But IsEnabled
is not assigned the value I need. For example:
I tried setting the value with Binding Path
and Binding Source
but nothing is working.
Please advise what may be wrong.
Then... I think must be so.
class Model : INotifyPropertyChanged
{
public bool enabled;
public bool IsLoggedIn
{
get
{
return enabled;
}
set
{
enabled = value;
OnPropertyChanged("IsLoggedIn");
}
}
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged([CallerMemberName]string property = "")
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(property));
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With