private static void UpdateContent(Control container, object value, IDataTemplateSelector selector) { if (selector != null) { value = selector.SelectTemplateWithContext(value, container); } var content = value as Control; if (content == null) { var viewModel = value as IViewModel; if (viewModel != null) { content = ViewModelToViewConverter.Instance.Convert(viewModel) as Control; } } if (content == null && value != null) { Tracer.Warn("The content value {0} is not a Control.", value); content = new TextBox { ReadOnly = true, Text = value.ToString(), Multiline = true }; } IContentViewManager viewManager = ContentViewManagerMember.GetValue(container, null); if (viewManager == null) { container.Controls.Clear(); if (content != null) { content.Dock = DockStyle.Fill; content.AutoSize = true; container.Size = content.Size; container.Controls.Add(content); } } else { viewManager.SetContent(container, content); } }
private static void UpdateContent(UIView container, object value, IDataTemplateSelector selector) { var viewController = ServiceProvider .AttachedValueProvider .GetValue <UIViewController>(container, ContentControllerPath, false); if (viewController != null) { viewController.RemoveFromParentViewController(); ServiceProvider.AttachedValueProvider.Clear(container, ContentControllerPath); viewController.InititalizeRestorationIdentifier(); } if (selector != null) { value = selector.SelectTemplateWithContext(value, container); } var viewModel = value as IViewModel; if (viewModel != null) { value = ViewModelToViewConverter.Instance.Convert(viewModel); } var view = value as UIView; if (view == null) { viewController = value as UIViewController; if (viewController == null) { if (value != null) { view = new UITextView(new RectangleF(4, 4, 300, 30)) { Editable = false, DataDetectorTypes = UIDataDetectorType.None, Text = value.ToString() } } ; } else { var currentController = container.FindParent <UIViewController>(); if (currentController != null) { ServiceProvider.AttachedValueProvider.SetValue(container, ContentControllerPath, viewController); viewController.WillMoveToParentViewController(currentController); currentController.AddChildViewController(viewController); viewController.DidMoveToParentViewController(currentController); viewController.RestorationIdentifier = string.Empty; view = viewController.View; } } } IContentViewManager viewManager = ContentViewManagerMember.GetValue(container, null); if (viewManager == null) { container.ClearSubViews(); if (view != null) { view.Frame = container.Frame; view.AutoresizingMask = UIViewAutoresizing.All; container.AddSubviewEx(view); } } else { viewManager.SetContent(container, view); } }