Quantcast
Channel: Caliburn.Micro: Xaml Made Easy
Viewing all articles
Browse latest Browse all 1760

New Post: Login view - Login button is not disabled initially based on CanLogin value, untill we click it for the first time.

$
0
0
Hi people,

I just started looking into Caliburn Micro and I started up with a simple login page implementation.
My page xaml looks like this
<StackPanel Grid.Column="1" Grid.Row="1">
            <StackPanel Orientation="Horizontal"
                        Margin="2">
                <TextBlock Text="Login name"
                           Width="100"/>
                <TextBox x:Name="LoginName" 
                         Width="200" />
            </StackPanel>
            <StackPanel Orientation="Horizontal"
                        Margin="2">
                <TextBlock Text="Password" 
                           Width="100"/>
                <TextBox x:Name="Password" 
                         Width="200" />
            </StackPanel>
            <Button x:Name="Login" 
                    Content="Submit"
                    Width="100"
                    Margin="2"/>
        </StackPanel>
And my view model class looks like this
public class LoginViewModel : PropertyChangedBase
    {
        private string loginName;
        public string LoginName
        {
            get
            {
                return loginName;
            }
            set
            {
                loginName = value;
                NotifyOfPropertyChange(() => LoginName);
                NotifyOfPropertyChange(() => CanLogin);
            }
        }

        private string password;
        public string Password
        {
            get { return password; }
            set
            {
                password = value;
                NotifyOfPropertyChange(() => Password);
                NotifyOfPropertyChange(() => CanLogin);
            }
        }

        public bool CanLogin
        {
            get
            {
                return !string.IsNullOrWhiteSpace(LoginName) && !string.IsNullOrWhiteSpace(Password);
            }
        }

        public void Login()
        {

        }
    }
I am not sure if there are any mistakes in this.
But until I click the login for the first time, the login button is always enabled.

Please help me fix this.

Viewing all articles
Browse latest Browse all 1760

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>