/// <summary> /// Sets the content. /// </summary> public static object SetContentView([NotNull] this ViewGroup frameLayout, object content, int?templateId, IDataTemplateSelector templateSelector) { content = GetContentView(frameLayout, frameLayout.Context, content, templateId, templateSelector); frameLayout.SetContentView(content); return(content); }
/// <summary> /// Sets the content. /// </summary> public static object SetContentView([NotNull] this ViewGroup frameLayout, object content, int?templateId, IDataTemplateSelector templateSelector, FragmentTransaction transaction = null, Action <ViewGroup, Fragment, FragmentTransaction> updateAction = null) { content = GetContentView(frameLayout, frameLayout.Context, content, templateId, templateSelector); frameLayout.SetContentView(content, transaction, updateAction); return(content); }
private void BuildChildren(IEnumerable items, int startingIndex) { IList <View> children = Layout?.Children; if (children == null || items == null) { return; } IDataTemplateSelector templateSel = ItemTemplateSelector; if (templateSel == null && ItemTemplate == null) { templateSel = new DefaultTemplateSelector(this); } if (templateSel != null) { foreach (object item in ItemsSource) { children.Insert(startingIndex++, CreateItemView(item, templateSel.SelectTemplate(item, this))); } } else { DataTemplate template = ItemTemplate; foreach (object item in ItemsSource) { children.Insert(startingIndex++, CreateItemView(item, template)); } } }
internal static object SelectTemplateWithContext(this IDataTemplateSelector selector, [CanBeNull] object item, [NotNull] object container) { object template = selector.SelectTemplate(item, container); if (template != null && item != null) { BindingServiceProvider.ContextManager.GetBindingContext(template).Value = item; } return(template); }
private void UpdateValues() { if (_templateSelectorMember != null) { var value = _templateSelectorMember.GetValue(_container, Empty.Array <object>()); _resourceSelector = value as IResourceDataTemplateSelector; _templateSelector = value as IDataTemplateSelector; } if (_templateMember != null) { _templateId = _templateMember.GetValue(_container, Empty.Array <object>()) as int?; } }
internal static object SelectTemplateWithContext(this IDataTemplateSelector selector, [CanBeNull] object item, [NotNull] object container) { var template = selector.SelectTemplate(item, container); if (template != null) { template.SetDataContext(item); if (!(template is Control) && !(template is ToolStripItem) && template.GetBindingMemberValue(AttachedMembersBase.Object.Parent) == null) { template.SetBindingMemberValue(AttachedMembersBase.Object.Parent, container); } } return(template); }
internal static object SelectTemplateWithContext(this IDataTemplateSelector selector, [CanBeNull] object item, [NotNull] object container) { object template = selector.SelectTemplate(item, container); if (template != null) { template.SetDataContext(item); if (!(template is UIView) && template.GetBindingMemberValue(AttachedMembers.Object.Parent, container) == null) { template.SetBindingMemberValue(AttachedMembers.Object.Parent, container); } } return(template); }
private void PerformTabBinding() { if (page == null) { return; } page.Children.Clear(); if (ItemsSource != null) { IDataTemplateSelector selector = ItemTemplateSelector; foreach (object item in ItemsSource) { Page pg = CreateTabItemPage(item, selector?.SelectTemplate(item, page)); page.Children.Add(pg); } } }
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(Control container, object value, IDataTemplateSelector selector) { if (selector != null) { value = selector.SelectTemplateWithContext(value, container); } var viewModel = value as IViewModel; if (viewModel != null) { value = ViewModelToViewConverter.Instance.Convert(viewModel); } var viewManager = container.GetBindingMemberValue(AttachedMembers.Control.ContentViewManager); if (viewManager == null) { container.Controls.Clear(); var content = value as Control; if ((content == null) && (value != null)) { content = new TextBox { ReadOnly = true, Text = value.ToString(), Multiline = true } } ; if (content != null) { content.Dock = DockStyle.Fill; content.AutoSize = true; container.Size = content.Size; container.Controls.Add(content); } } else { viewManager.SetContent(container, value); } }
private void ShowInternal(ToastImpl toast, IDataTemplateSelector selector, View snackbarHolderView, object content, float duration, ToastPosition position, IDataContext context) { Snackbar snackbar; if (selector == null) { snackbar = Snackbar.Make(snackbarHolderView, content.ToStringSafe("(null)"), (int)duration); } else { snackbar = (Snackbar)selector.SelectTemplate(content, snackbarHolderView); } if (snackbar == null) { toast.FromToast(_defaultPresenter.ShowAsync(content, duration, position, context)); } else { toast.Show(snackbar, duration); } }
private void OnItemsSourceCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { if (page == null) { return; } IDataTemplateSelector selector = ItemTemplateSelector; if (e.Action == NotifyCollectionChangedAction.Reset) { page.Children.Clear(); } else if (e.Action == NotifyCollectionChangedAction.Add) { int idx = e.NewStartingIndex; foreach (object item in e.NewItems) { page.Children.Insert(idx++, CreateTabItemPage(item, selector?.SelectTemplate(item, page))); } } else if (e.Action == NotifyCollectionChangedAction.Remove) { foreach (object item in e.OldItems) { page.Children.RemoveAt(e.OldStartingIndex); } } else if (e.Action == NotifyCollectionChangedAction.Replace) { int idx = e.NewStartingIndex; foreach (object item in e.NewItems) { page.Children[idx++] = CreateTabItemPage(item, selector?.SelectTemplate(item, page)); } } else { throw new NotSupportedException(e.Action.ToString()); } }
public IViewBinder <TData> WithDataTemplateSelector <T>() where T : IDataTemplateSelector <TData>, new() { this.DataTemplateSelector = Cache <T> .Instance; return(this); }
private static object GetContentInternal(object container, Context ctx, object content, IDataTemplateSelector templateSelector) { var template = templateSelector.SelectTemplate(content, container); if (template is int) { return(GetContentInternal(ctx, content, (int)template)); } if (content != null && (template is View || IsFragment(template))) { template.SetDataContext(content); } return(template); }
public static object GetContentView(object container, Context ctx, object content, int?templateId, IDataTemplateSelector templateSelector) { Should.NotBeNull(container, "container"); object result; if (templateSelector != null) { result = GetContentInternal(container, ctx, content, templateSelector); #if API8 if (result is View) #else if (result is View || result is Fragment) #endif { return(result); } content = result; } if (templateId != null) { result = GetContentInternal(ctx, content, templateId); return(result); } var vm = content as IViewModel; if (vm != null) { content = GetOrCreateView(vm, null); } #if API8 if (content is View) #else if (content is View || content is Fragment) #endif { return(content); } var selector = DefaultDataTemplateSelector; if (selector != null) { result = GetContentInternal(container, ctx, content, templateSelector); #if API8 if (result is View) #else if (result is View || result is Fragment) #endif { return(result); } content = result; } if (content == null) { return(null); } Tracer.Warn("The content value {0} is not a View or Fragment.", content); result = new TextView(ctx) { Text = content.ToString() }; return(result); }
private static object GetContentInternal(object container, Context ctx, object content, IDataTemplateSelector templateSelector) { object template = templateSelector.SelectTemplate(content, container); var newView = template as View; if (newView != null) { BindingServiceProvider.ContextManager.GetBindingContext(newView).Value = content; return(newView); } if (template is int) { return(GetContentInternal(ctx, content, (int)template)); } #if !API8 var fragment = template as Fragment; if (fragment != null) { BindingServiceProvider.ContextManager.GetBindingContext(fragment).Value = content; return(fragment); } #endif return(template); }
public IViewBinder <TData> WithDataTemplate(int resourceId) { this.DataTemplateSelector = new SingleDataTemplateSelector <TData>(resourceId); return(this); }
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); viewController = value as UIViewController; if (viewController != null) { var currentController = container.FindParent<UIViewController>(); if (currentController != null) { ServiceProvider.AttachedValueProvider.SetValue(container, ContentControllerPath, viewController); viewController.WillMoveToParentViewController(currentController); currentController.AddChildViewController(viewController); viewController.DidMoveToParentViewController(currentController); PlatformExtensions.SetHasState(viewController, false); value = viewController.View; } } var viewManager = container.GetBindingMemberValue(AttachedMembers.UIView.ContentViewManager); if (viewManager == null) { container.ClearSubViews(); var view = value as UIView; if (view == null && value != null) view = new UITextView(container.Frame) { Editable = false, DataDetectorTypes = UIDataDetectorType.None, Text = value.ToString() }; if (view != null) { view.Frame = container.Frame; view.AutoresizingMask = UIViewAutoresizing.All; container.AddSubviewEx(view); } } else viewManager.SetContent(container, value); }
private void UpdateValues() { if (_templateSelectorMember != null) { var value = _templateSelectorMember.GetValue(_container, Empty.Array<object>()); _resourceSelector = value as IResourceDataTemplateSelector; _templateSelector = value as IDataTemplateSelector; } if (_templateMember != null) _templateId = _templateMember.GetValue(_container, Empty.Array<object>()) as int?; }
private void ShowInternal(ToastImpl toast, IDataTemplateSelector selector, View snackbarHolderView, object content, float duration, ToastPosition position, IDataContext context) { Snackbar snackbar; if (selector == null) snackbar = Snackbar.Make(snackbarHolderView, content.ToStringSafe("(null)"), (int)duration); else snackbar = (Snackbar)selector.SelectTemplate(content, snackbarHolderView); if (snackbar == null) toast.FromToast(_defaultPresenter.ShowAsync(content, duration, position, context)); else toast.Show(snackbar, duration); }
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); } viewController = value as UIViewController; if (viewController != null) { var currentController = container.FindParent <UIViewController>(); if (currentController != null) { ServiceProvider.AttachedValueProvider.SetValue(container, ContentControllerPath, viewController); viewController.WillMoveToParentViewController(currentController); currentController.AddChildViewController(viewController); viewController.DidMoveToParentViewController(currentController); TouchToolkitExtensions.SetHasState(viewController, false); value = viewController.View; } } var viewManager = container.GetBindingMemberValue(AttachedMembers.UIView.ContentViewManager); if (viewManager == null) { container.ClearSubViews(); var view = value as UIView; if ((view == null) && (value != null)) { view = new UITextView(container.Frame) { Editable = false, DataDetectorTypes = UIDataDetectorType.None, Text = value.ToString() } } ; if (view != null) { view.Frame = container.Frame; view.AutoresizingMask = UIViewAutoresizing.All; container.AddSubviewEx(view); } } else { viewManager.SetContent(container, value); } }
private static void UpdateContent(Control container, object value, IDataTemplateSelector selector) { if (selector != null) value = selector.SelectTemplateWithContext(value, container); var viewModel = value as IViewModel; if (viewModel != null) value = ViewModelToViewConverter.Instance.Convert(viewModel); var viewManager = container.GetBindingMemberValue(AttachedMembers.Control.ContentViewManager); if (viewManager == null) { container.Controls.Clear(); var content = value as Control; if (content == null && value != null) content = new TextBox { ReadOnly = true, Text = value.ToString(), Multiline = true }; if (content != null) { content.Dock = DockStyle.Fill; content.AutoSize = true; container.Size = content.Size; container.Controls.Add(content); } } else viewManager.SetContent(container, value); }