zoukankan      html  css  js  c++  java
  • Xamarin.iOS中使用MvvmLight框架

    Xamarin.iOS中使用MvvmLight框架

    如何在Xamarin.iOS 中使用MvvmLight框架:

    1. 通过NuGet包管理器安装MvvmLight包

    2. 创建对应的ViewModel

    3. 在Controller中使用ViewModel(需要在Controller中添加引用:using GalaSoft.MvvmLight.Helpers 才能使用binding技术

    UpdateTargetTrigger方法已经不被推荐使用,推荐使用ObserveTargetEvent。

    ViewModel:

    public class TextViewModel : ViewModelBase
    {
        private string text;
     
        public string Text
        {
            get { return text; }
            set { 
            if (value != _text)
                 {
                     _text= value;
                     RaisePropertyChanged("Text");
                 }
          } } }

    UIViewController:

    需要在Controller中添加引用:

    using GalaSoft.MvvmLight.Helpers;

    public class TextViewController : UIViewController
        {
            private TextViewModel textViewModel;
     
            private Binding<string, string> textFieldBinding;
            private UITextField textField;
     
            private UITextField TextField
            {
                get { return textField; }
            }
     
            private TextViewModel TextViewModel
            {
                get { return textViewModel; }
            }
     
            public override void ViewDidLoad()
            {
                base.ViewDidLoad();
                textViewModel = new TextViewModel();
     
                textField = new UITextField(new CoreGraphics.CGRect(20, 75, 280, 40));
                textField.BackgroundColor = UIColor.White;
     
                textFieldBinding = this.SetBinding(
                    () => TextViewModel.Text,
                    () => TextField.Text,
                    BindingMode.TwoWay)
                    .ObserveTargetEvent(nameof(UITextField.EditingChanged));
     
                View.AddSubview(textField);
            }
        }

     UISlider:

     this.SetBinding(() => mDetailViewModel.PasswordLength, () => SliderCount.Value, BindingMode.TwoWay).ObserveTargetEvent(nameof(UISlider.ValueChanged));

    BEMCheckBox:

    this.SetBinding(() => mDetailViewModel.CheckLower, () => CheckBoxContainer.CheckBoxLower.On, BindingMode.TwoWay).ObserveTargetEvent(nameof(BEMCheckBox.AnimationDidStopForCheckBox));
  • 相关阅读:
    深拷贝浅拷贝
    计算属性和监听,computed,watch
    字面量的引用与使用
    MYSQL 触发器
    JavaScript寻找对象方式
    JavaScript事件传播
    HTML 绑定事件
    JavaScript 中的 String()方法
    JavScript re模块
    JavScript Math函数的使用方法
  • 原文地址:https://www.cnblogs.com/devin_zhou/p/8086419.html
Copyright © 2011-2022 走看看