public bool TrySelectTemplate(object value, out object template) { template = null; if (_templateSelector == null) { return(false); } template = _templateSelector.SelectTemplate(value, _container); return(true); }
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 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()); } }
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); }
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 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 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); }
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); }