Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XAML Binding to property

I have check box in my XAML+C# Windows Store application. Also I have bool property: WindowsStoreTestApp.SessionData.RememberUser which is public and static.

I want check box's property IsChecked to be consistent (or binded, or mapped) to this bool property.

I tried this: XAML

<CheckBox x:Name="chbRemember1"  IsChecked="{Binding Mode=TwoWay}"/>

C#

chbRemember1.DataContext = SessionData.RememberUser;

Code for property:

namespace WindowsStoreTestApp
{
    public class SessionData
    {
        public static bool RememberUser { get; set; }
    }
}

But it doesn't seem to work. Can you help me?

like image 993
imslavko Avatar asked Dec 05 '12 22:12

imslavko


1 Answers

<CheckBox x:Name="chbRemember1"  IsChecked="{Binding Path=RememberUser, Mode=TwoWay}"/>

 

public class SessionData : INotifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;
    private void NotifyPropertyChanged(string info)
    {
        if (PropertyChanged != null)
            PropertyChanged(this, new PropertyChangedEventArgs(info));
    }


    bool _rememberUser;
    public bool RememberUser
    {
        get
        {
            return _rememberUser;
        }
        set
        {
            _rememberUser = value;
            NotifyPropertyChanged("RememberUser");
        }
    }
}
like image 104
patrick Avatar answered Sep 18 '22 21:09

patrick