Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MvvmLight bindings in code?

Is it possible to do the mvvm-light bindings in code in xamarin forms?

I want to do this to be typesafe. If so, is it possible to show me an example?

like image 652
BrunoVT Avatar asked Jun 29 '26 07:06

BrunoVT


2 Answers

I've set the binding like this:

button.SetBinding (Button.CommandParameterProperty, "ButtonCommand");

Where the "ButtonCommand" is defined like this in my ViewModel:

public RelayCommand buttonCommand;

public RelayCommand ButtonCommand {
    get {
        ....
    }
}
like image 190
pnavk Avatar answered Jun 30 '26 22:06

pnavk


For a typesafe solution:

In your page:

MyButton.SetBinding<FooViewModel>(ActivityIndicator.IsRunningProperty, model => model.IsBusy);

In your FooViewModel

    bool _isBusy;
    public bool IsBusy
    {
        get { return _isBusy; }
        set
        {
            Set(ref _isBusy, value);
            LoginCommand.RaiseCanExecuteChanged();
        }
    }
like image 31
vvolkgang Avatar answered Jun 30 '26 22:06

vvolkgang



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!