How to set binding in xaml to my own variable
Posted
by Victor
on Stack Overflow
See other posts from Stack Overflow
or by Victor
Published on 2010-03-19T19:20:01Z
Indexed on
2010/03/19
19:21 UTC
Read the original article
Hit count: 620
Hello. I have an object in the code:
public class UserLogin
{
bool _IsUserLogin = false;
public bool IsUserLogin
{
get { return _IsUserLogin; }
set { _IsUserLogin = value; }
}
public UserLogin()
{
_IsUserLogin = false;
}
}
....
public static UserLogin LoginState;
.....
LoginState = new UserLogin();
And I need to set bindings to Button.IsEnabled property. I.e. when user not login yet - some buttons are disabled. How can this been done? I have try in xaml:
<Button DataContext="LoginState" IsEnabled="{Binding Path=IsUserLogin}">
but, this dos't work and OutputWindow says: System.Windows.Data Error: 39 : BindingExpression path error: 'IsUserLogin' property not found on 'object'. I also have try to set Button.DataContext property to LoginState in the code, but have XamlParseException. I also read this one [http://stackoverflow.com/questions/1829758/wpf-binding-in-xaml-to-an-object-created-in-the-code-behind][1] but still can't set bindings.
[1]: http://stackoverflow.com/questions/1829758/wpf-binding-in-xaml-to-an-object-created-in-the-code-behind. Please help!
© Stack Overflow or respective owner