public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            // TargetNullValue and FallbackValue ------------------------------------------------------------

            #region TargetNullValue and FallbackValue

            _binding = this.SetBinding(
                () => Vm.Model.MyModelProperty,
                () => MyLabelA1.Text,
                fallbackValue: "Model object is null",
                targetNullValue: "Value is null");

            MyButtonA1.SetCommand(Vm.SetModelPropertyCommand);

            #endregion

            #region Subscribing to events to avoid linker issues in release mode

            // This "fools" the linker into believing that the events are used.
            // In fact we don't even subscribe to them.
            // See https://developer.xamarin.com/guides/android/advanced_topics/linking/

            if (_falseFlag)
            {
                MyButtonA1.TouchUpInside += (s, e) => { };
            }

            #endregion
        }
예제 #2
0
 void ReleaseDesignerOutlets()
 {
     if (MyButtonA1 != null)
     {
         MyButtonA1.Dispose();
         MyButtonA1 = null;
     }
     if (MyLabelB1 != null)
     {
         MyLabelB1.Dispose();
         MyLabelB1 = null;
     }
     if (MySwitchA1 != null)
     {
         MySwitchA1.Dispose();
         MySwitchA1 = null;
     }
     if (MySwitchC1 != null)
     {
         MySwitchC1.Dispose();
         MySwitchC1 = null;
     }
     if (MySwitchC2 != null)
     {
         MySwitchC2.Dispose();
         MySwitchC2 = null;
     }
     if (MyTextFieldB1 != null)
     {
         MyTextFieldB1.Dispose();
         MyTextFieldB1 = null;
     }
 }
 void ReleaseDesignerOutlets()
 {
     if (MyButtonA1 != null)
     {
         MyButtonA1.Dispose();
         MyButtonA1 = null;
     }
     if (MyLabelA1 != null)
     {
         MyLabelA1.Dispose();
         MyLabelA1 = null;
     }
 }
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Bindings);

            // Simple bindings ------------------------------------------------------------------------------

            #region Simple Bindings

            var binding1 = this.SetBinding(
                () => Vm.MyBoolProperty,     // This is a VM --> PropertyChanged event
                () => MyCheckBoxA1.Checked); // will be used.

            MyButtonA1.SetCommand(Vm.ToggleCommand);

            var binding2 = this.SetBinding(
                () => MyEditTextB1.Text,  // This is an EditText --> TextChanged event
                () => MyTextViewB1.Text); // will be used.

            var binding3 = this.SetBinding(
                () => MyCheckBoxC1.Checked,  // This is a CheckBox --> CheckedChange event
                () => MyCheckBoxC2.Checked); // will be used.

            #endregion

            // Bindings with custom events ------------------------------------------------------------------

            #region Bindings with custom events

            var binding4 = this.SetBinding(
                () => MyEditTextD1.Text,
                () => MyTextViewD1.Text)
                           .ObserveSourceEvent("Click");

            var binding5 = this.SetBinding(
                () => MyEditTextE1.Text,
                () => MyTextViewE1.Text)
                           .ObserveSourceEvent <View.FocusChangeEventArgs>("FocusChange");

            #endregion

            // Conversion back and forth --------------------------------------------------------------------

            #region Conversion back and forth

            var binding6 = this.SetBinding(
                () => MyCheckBoxF1.Checked,
                () => MyEditTextF1.Text,
                BindingMode.TwoWay);

            var binding7 = this.SetBinding(
                () => MyCheckBoxG1.Checked,
                () => MyEditTextG1.Text,
                BindingMode.TwoWay)
                           .ConvertSourceToTarget(val => val ? "TTT" : "FFF")
                           .ConvertTargetToSource(val => val == "TTT");

            #endregion

            // When Source Changes --------------------------------------------------------------------------

            #region When Source Changes

            _binding8 = this.SetBinding(() => MyCheckBoxH1.Checked)
                        .WhenSourceChanges(
                () =>
            {
                MyTextViewH1.Text = MyCheckBoxH1.Checked.ToString();

                if (_binding8 == null)
                {
                    MyCheckBoxH1.Text = "Binding is null";
                }
                else
                {
                    MyCheckBoxH1.Text = "Binding value is " + _binding8.Value;
                }
            });

            #endregion

            // TargetNullValue and FallbackValue ------------------------------------------------------------

            #region Saving bindings

            _bindings.Add(binding1);
            _bindings.Add(binding2);
            _bindings.Add(binding3);
            _bindings.Add(binding4);
            _bindings.Add(binding5);
            _bindings.Add(binding6);
            _bindings.Add(binding7);
            _bindings.Add(_binding8);
            //_bindings.Add(_binding9);

            #endregion

            #region TargetNullValue and FallbackValue

            _bindings.Add(this.SetBinding(
                              () => Vm.Model.MyModelProperty,
                              () => MyTextViewJ1.Text,
                              fallbackValue: "Model object is null",
                              targetNullValue: "Value is null"));

            MyButtonJ1.SetCommand(Vm.SetModelPropertyCommand);

            #endregion

            // Subscribing to events to avoid linker issues in release mode ---------------------------------

            #region Subscribing to events to avoid linker issues in release mode

            // This "fools" the linker into believing that the events are used.
            // In fact we don't even subscribe to them.
            // See https://developer.xamarin.com/guides/android/advanced_topics/linking/

            if (_falseFlag)
            {
                MyCheckBoxA1.CheckedChange += (s, e) => { };
                MyCheckBoxC1.CheckedChange += (s, e) => { };
                MyCheckBoxF1.CheckedChange += (s, e) => { };
                MyCheckBoxG1.CheckedChange += (s, e) => { };
                MyCheckBoxH1.CheckedChange += (s, e) => { };

                MyEditTextB1.TextChanged += (s, e) => { };
                //MyEditTextI1.TextChanged += (s, e) => { };
                MyEditTextD1.Click       += (s, e) => { };
                MyEditTextE1.FocusChange += (s, e) => { };

                MyButtonA1.Click += (s, e) => { };
            }

            #endregion
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            var nextButton = new UIBarButtonItem(
                "Next",
                UIBarButtonItemStyle.Plain,
                (s, e) =>
            {
                Nav.NavigateTo(AppDelegate.BindingsPage2Key);
            });

            NavigationItem.SetRightBarButtonItem(nextButton, false);

            View.AddGestureRecognizer(
                new UITapGestureRecognizer(
                    () =>
            {
                if (MyTextFieldB1.CanResignFirstResponder)
                {
                    MyTextFieldB1.ResignFirstResponder();
                }
            }));

            // Simple bindings ------------------------------------------------------------------------------

            #region Simple Bindings

            _bindings.Add(
                this.SetBinding(
                    () => Vm.MyBoolProperty,
                    // This is a VM --> PropertyChanged event
                    () => MySwitchA1.On)); // will be used.

            MyButtonA1.SetCommand(Vm.ToggleCommand);

            _bindings.Add(
                this.SetBinding(
                    () => MyTextFieldB1.Text,
                    // This is an TextField --> EditingChanged event
                    () => MyLabelB1.Text)); // will be used.

            _bindings.Add(
                this.SetBinding(
                    () => MySwitchC1.On,
                    // This is a CheckBox --> ValueChanged event
                    () => MySwitchC2.On)); // will be used.

            #endregion

            #region Subscribing to events to avoid linker issues in release mode

            // This "fools" the linker into believing that the events are used.
            // In fact we don't even subscribe to them.
            // See https://developer.xamarin.com/guides/android/advanced_topics/linking/

            if (_falseFlag)
            {
                MyTextFieldB1.EditingChanged += (s, e) =>
                {
                };
                MySwitchC1.ValueChanged += (s, e) =>
                {
                };
            }

            #endregion
        }