0

I have created Android app which is working as expected. Now I added UWP Project as shown in MvvmCross site.

The problem is that binding is not working there.

There is my XAML:

  <Grid Row="1" >
            <StackPanel VerticalAlignment="Center"
                        Margin="40 0 40 0">
                <TextBox Text="{Binding Login}"
                         Margin="0 0 0 20"/>
                <PasswordBox Password="{Binding Password}"/>
            </StackPanel>
            <Button VerticalAlignment="Bottom"
                    Content="Login"
                    Command="{Binding LoginCommand}"
                    Foreground="#F9F9F9"
                    HorizontalAlignment="Stretch"
                    Background="#FF4081"/>
        </Grid>

And ViewModel

        public string Login { get; set; }

        public string Password { get; set; }

        public MvxCommand LoginCommand { get; private set; }
//...

When Login button is pressed it succesfully goes into given method but Login and Password string are null. The same code is working for Android with MvxBind on Login and Password strings.

Do I do something worng ?

miechooy
  • 3,178
  • 12
  • 34
  • 59
  • Are you using Fody PropertyChanged? If that´s the case, make sure the wave xml is correct in the UWP project – xleon Feb 28 '17 at 00:12
  • And BTW, if you don´t show how you do bindings, people won´t be able to help much – xleon Feb 28 '17 at 00:14

3 Answers3

0

When Login button is pressed it succesfully goes into given method but Login and Password string are null

In you code I did not recognize you have implemented the Login property set get method. Neither you have included RaisePropertyChanged(() => ). So you could try to use the code below and check whether it works or not. At the meantime you may refer to the project I uploaded.

public class MainViewModel : MvxViewModel
{
    private string _login;
    private string _password;

    public string Login
    {
        get { return _login; }
        set { _login = value; RaisePropertyChanged(() => Login); }
    }

    public string Password
    {
        get { return _password; }
        set { _password = value; RaisePropertyChanged(() => Password); }
    }

    public ICommand LoginAction
    {
        get
        {
            return new MvxCommand(() => ShowViewModel<HomeViewModel>(new {Login,Password}));
        }
    }
}
Nico Zhu
  • 32,367
  • 2
  • 15
  • 36
0

I know this is 4 years ago but for future readers, in UWP Passwordbox doesn't expose Password DP the reason is that it is unsecure to have passwords in memory.

So you should violate mvvm and put password in Database from code behind. And here is some helpful links:

How to bind to a PasswordBox in MVVM http://blog.functionalfun.net/2008/06/wpf-passwordbox-and-data-binding.html

Also if you insist to expose password you can create your own control.

Said Amir
  • 36
  • 6
-1

Speaking generically to WPF, your ViewModel properties need to implement INotifyPropertyChanged found in System.ComponentModel in order for bindings to update the UI. Add this bit of code to your viewmodel and rework your properties as shown by Login below:

public class ViewModel:INofifyPropertyChanged
{
    public event PropertyChangedEventHandler PropertyChanged;

    private void notifyPropertyChanged(string name)
    {
        if(PropertyChanged != null)
        {
            PropertyChanged(this, new PropertyChangedEventArgs(name));
        }
    }

    private string _login;
    public string Login
    {
        get
        {
            return _login;
        }
        set
        {
            _login = value;
            notifyPropertyChanged("Login");
        }
    }
}
NWoodsman
  • 423
  • 4
  • 10