当前位置: 首页>>代码示例>>C#>>正文


C# DataBinding.UpdateViewModel方法代码示例

本文整理汇总了C#中DataBinding.UpdateViewModel方法的典型用法代码示例。如果您正苦于以下问题:C# DataBinding.UpdateViewModel方法的具体用法?C# DataBinding.UpdateViewModel怎么用?C# DataBinding.UpdateViewModel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DataBinding的用法示例。


在下文中一共展示了DataBinding.UpdateViewModel方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddTwoWayHandler

        private void AddTwoWayHandler(DataBinding binding)
        {
            if (binding.ViewProperty == null || binding.ViewProperty.ContainingObject == null) return;
            var view = binding.ViewProperty.ContainingObject;
            string viewTypeName = view.GetType().FullName;
            switch (viewTypeName)
            {
                // TODO: Add cases here for specialized view types, as needed
                case "MonoTouch.UIKit.UITextField":
                    if (textFieldTextDidChangeObserver == null) {
                        textFieldTextDidChangeObserver = NSNotificationCenter.DefaultCenter.AddObserver(
                            UITextField.TextFieldTextDidChangeNotification, HandleTextFieldTextDidChangeNotification
                        );
                    }
                    break;
                case "MonoTouch.UIKit.UITextView" : ((UITextView)view).Changed += HandleTextViewChanged;
                    break;

                #if __DIALOG__
                case "MonoTouch.Dialog.EntryElement": {
                        var element = (EntryElement)view;
                        element.Changed += (s, e) => binding.UpdateViewModel(viewModel, element.Value);
                    }
                    break;
                case "MonoTouch.Dialog.BooleanElement":
                case "MonoTouch.Dialog.BooleanImageElement":
                    {
                        var element = (BoolElement)view;
                        element.ValueChanged += (s, e) => binding.UpdateViewModel(viewModel, element.Value);
                    }
                    break;
                case "MonoTouch.Dialog.CheckboxElement":
                    {
                        var element = (CheckboxElement)view;
                        element.Tapped += () => binding.UpdateViewModel(viewModel, element.Value);
                    }
                    break;
                case "MonoTouch.Dialog.DateTimeElement":
                case "MonoTouch.Dialog.DateElement":
                case "MonoTouch.Dialog.TimeElement":
                    {
                        var element = (DateTimeElement)view;
                        element.DateSelected += (d) => binding.UpdateViewModel(viewModel, d.DateValue);
                    }
                    break;
                case "MonoTouch.Dialog.RootElement":
                    {
                        var rootElement = (RootElement)view;
                        foreach (var section in rootElement)
                        {
                            foreach (var element in section.Elements)
                            {
                                var radioElement = element as RadioElement;
                                if (radioElement != null)
                                {
                                    radioElement.Tapped += () =>
                                    {
                                        if (binding.ViewModelListPropertyInfo != null)
                                        {
                                            var list = binding.ViewModelListPropertyInfo.GetValue(viewModel) as IList;
                                            int i = rootElement.RadioSelected;
                                            if (list != null && i >= 0 && i < list.Count) binding.UpdateViewModel(viewModel, list[i]);
                                        }
                                    };
                                }
                            }
                        }
                    }
                    break;
                #endif

                default:
                    if (view is UITableView) break;
                    throw new NotImplementedException("View type not implemented: " + viewTypeName);
            }
        }
开发者ID:rvdplas,项目名称:QuickCross,代码行数:76,代码来源:ViewDataBindings.UI.cs


注:本文中的DataBinding.UpdateViewModel方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。