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.
IsLoggedIn
must be a property in the View Model, not in the View code behind (and if your data context is the View then revert it now...)DependencyProperty
or implementINotifyPropertyChanged