Exemplo n.º 1
0
        private void DisconnectPropertyBindingSetting(PropertyBindingSettings setting)
        {
            var prop = typeof(T).GetProperty(setting.BindingObject, BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public);

            if (prop != null)
            {
                if (!string.IsNullOrEmpty(setting.EventName))
                {
                    var instance      = prop.GetValue(controller);
                    var eventInstance = instance.GetType().GetEvent(setting.EventName);
                    if (eventInstance != null)
                    {
                        var tDelegate = eventInstance.EventHandlerType;
                        var miHandler = this.GetType().GetMethod("InternalControlEventHandler", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public);
                        if (miHandler != null)
                        {
                            var             addHandler     = eventInstance.GetRemoveMethod();
                            var             d              = Delegate.CreateDelegate(tDelegate, this, miHandler);
                            System.Object[] addHandlerArgs = { d };
                            addHandler.Invoke(instance, addHandlerArgs);
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void InternalControlEventHandler(object sender, EventArgs args)
        {
            nint tag = 0;

            if (sender is UIControl)
            {
                tag = ((UIControl)sender).Tag;
            }
            else
            {
                if (sender is IBaseSource)
                {
                    tag = ((IBaseSource)sender).Tag;
                }
            }

            PropertyBindingSettings ctrl = null;

            if (args != null && args is RowSelectedEventArgs)
            {
                ctrl = pbs.FirstOrDefault(x => x.Tag == tag && x.EventName == "RowSelectedEvent");
            }
            else
            {
                ctrl = pbs.FirstOrDefault(x => x.Tag == tag);
            }

            if (ctrl != null)
            {
                var prop      = sender.GetType().GetProperty(ctrl.BindingProperty, BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public);
                var propValue = prop.GetValue(sender, null);
                var vmProp    = viewModel.GetType().GetProperty(ctrl.ViewModelProperty, BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public);

                if (sender is IBaseSource)
                {
                    var item = ((IBaseSource)sender).SelectedItem;
                    vmProp.SetValue(viewModel, item);
                }
                else
                {
                    var cvPropValue = ValueConverter.ChangeType(vmProp.PropertyType.Name, propValue.ToString());

                    if (cvPropValue == null)
                    {
                        return;
                    }

                    vmProp.SetValue(viewModel, cvPropValue);
                }
            }
        }
Exemplo n.º 3
0
        private void SetInitialValue(PropertyBindingSettings setting)
        {
            var vmProp      = viewModel.GetType().GetProperty(setting.ViewModelProperty, BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public);
            var cvPropValue = vmProp.GetValue(viewModel, null);

            var ctrlProp     = typeof(T).GetProperty(setting.BindingObject, BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public);
            var ctrlInstance = ctrlProp.GetValue(bindingObj);
            var prop         = ctrlInstance.GetType().GetProperty(setting.BindingProperty, BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public);

            prop.SetValue(ctrlInstance, cvPropValue);

            if (ctrlProp.PropertyType.Name == "EditText")
            {
                int textLength = ((EditText)ctrlInstance).Text.Length;
                ((EditText)ctrlInstance).SetSelection(textLength, textLength);
            }
        }
Exemplo n.º 4
0
        private void SetControlFromViewModel(PropertyBindingSettings setting)
        {
            var ctrlProp        = typeof(T).GetProperty(setting.BindingObject, BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public);
            var ctrlInstance    = ctrlProp.GetValue(controller);
            var ctrlInstaceProp = ctrlInstance.GetType().GetProperty(setting.BindingProperty, BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public);
            var currentValue    = ctrlInstaceProp.GetValue(ctrlInstance);
            var vmProp          = viewModel.GetType().GetProperty(setting.ViewModelProperty, BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public);
            var vmValue         = vmProp.GetValue(viewModel, null);

            if (!currentValue.Equals(vmValue))
            {
                if (ctrlInstance is IBaseSource)
                {
                    if (setting.EventName != "RowSelectedEvent")
                    {
                        ((IBaseSource)ctrlInstance).UpdateCollection((ICollection)vmValue);
                    }
                }
                else if (currentValue.GetType().Name != "String" && (currentValue.GetType().Name == vmValue.GetType().Name))
                {
                    ctrlInstaceProp.SetValue(ctrlInstance, vmValue);
                }
                else
                {
                    if (!string.IsNullOrEmpty(setting.Format))
                    {
                        var formattedValue = string.Format(setting.Format, vmValue);
                        ctrlInstaceProp.SetValue(ctrlInstance, formattedValue);
                    }
                    else
                    {
                        ctrlInstaceProp.SetValue(ctrlInstance, vmValue.ToString());
                    }
                }
            }
        }