【问题标题】:MvvmLight bindings in code?代码中的 MvvmLight 绑定?
【发布时间】:2015-05-19 07:39:28
【问题描述】:

是否可以在 xamarin 形式的代码中进行 mvvm-light 绑定?

我想这样做是为了类型安全。如果是这样,可以给我举个例子吗?

【问题讨论】:

  • 也许MvvmCross 会是更好的选择?
  • 嗨,我很担心,但我们只是决定编写自己的 mvvm frawemork :)

标签: c# xamarin mvvm-light xamarin-forms


【解决方案1】:

我已经这样设置了绑定:

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

“ButtonCommand”在我的 ViewModel 中是这样定义的:

public RelayCommand buttonCommand;

public RelayCommand ButtonCommand {
    get {
        ....
    }
}

【讨论】:

    【解决方案2】:

    对于类型安全的解决方案:

    在您的页面中:

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

    在您的 FooViewModel 中

        bool _isBusy;
        public bool IsBusy
        {
            get { return _isBusy; }
            set
            {
                Set(ref _isBusy, value);
                LoginCommand.RaiseCanExecuteChanged();
            }
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-08-25
      • 2016-09-22
      • 1970-01-01
      • 2018-07-17
      • 2011-07-10
      • 2015-11-19
      • 2016-03-13
      相关资源
      最近更新 更多