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));
  • 相关阅读:
    硬盘的结构和介绍,硬盘MBR详细介绍(超详细彩图)
    websocket协议学习
    Qt4可以使用trUtf8函数,其内容可以是中文,也可以是F硬编码
    QString转换为LPTSTR(使用了reinterpret_cast,真是叹为观止,但是也开阔了思路),三篇文章合起来的各种转换方法
    系统高可用
    Visual Studio
    管道是如何建立起来的?
    CLR和.Net对象
    任务调度
    路由与控制器
  • 原文地址:https://www.cnblogs.com/devin_zhou/p/8086419.html
Copyright © 2011-2022 走看看