public static (UIView NativeView, VisualElement FormsElement) RealizeView(object view, DataTemplate viewTemplate, ItemsView itemsView) { if (viewTemplate != null) { // Run this through the extension method in case it's really a DataTemplateSelector viewTemplate = viewTemplate.SelectDataTemplate(view, itemsView); // We have a template; turn it into a Forms view var templateElement = viewTemplate.CreateContent() as View; var renderer = CreateRenderer(templateElement); // and set the EmptyView as its BindingContext BindableObject.SetInheritedBindingContext(renderer.Element, view); return(renderer.NativeView, renderer.Element); } if (view is View formsView) { // No template, and the EmptyView is a Forms view; use that var renderer = CreateRenderer(formsView); return(renderer.NativeView, renderer.Element); } return(new UILabel { Text = $"{view}" }, null); }
public override int GetItemViewType(int position) { var item = _listItems[position]; DataTemplate dataTemplate = ShellController.GetFlyoutItemDataTemplate(item.Element); if (item.Element is IMenuItemController) { if (DefaultMenuItemTemplate != null && Shell.MenuItemTemplate == dataTemplate) { dataTemplate = DefaultMenuItemTemplate; } } else { if (DefaultItemTemplate != null && Shell.ItemTemplate == dataTemplate) { dataTemplate = DefaultItemTemplate; } } var template = dataTemplate.SelectDataTemplate(item.Element, Shell); var id = ((IDataTemplateController)template).Id; _templateMap[id] = template; return(id); }
public (UIView NativeView, VisualElement FormsElement) RealizeEmptyView(object emptyView, DataTemplate emptyViewTemplate) { if (emptyViewTemplate != null) { // Run this through the extension method in case it's really a DataTemplateSelector emptyViewTemplate = emptyViewTemplate.SelectDataTemplate(emptyView, _itemsView); // We have a template; turn it into a Forms view var templateElement = emptyViewTemplate.CreateContent() as View; var renderer = CreateRenderer(templateElement); // and set the EmptyView as its BindingContext BindableObject.SetInheritedBindingContext(renderer.Element, emptyView); return(renderer.NativeView, renderer.Element); } if (emptyView is View formsView) { // No template, and the EmptyView is a Forms view; use that var renderer = CreateRenderer(formsView); return(renderer.NativeView, renderer.Element); } // No template, EmptyView is not a Forms View, so just display EmptyView.ToString var label = new UILabel { Text = emptyView.ToString() }; return(label, null); }
DataTemplate GetDataTemplate(int viewTypeId) { AdapterListItem item = null; foreach (var ali in _listItems) { if (viewTypeId == ali.Index) { item = ali; break; } } DataTemplate dataTemplate = ShellController.GetFlyoutItemDataTemplate(item.Element); if (item.Element is IMenuItemController) { if (DefaultMenuItemTemplate != null && Shell.MenuItemTemplate == dataTemplate) { dataTemplate = DefaultMenuItemTemplate; } } else { if (DefaultItemTemplate != null && Shell.ItemTemplate == dataTemplate) { dataTemplate = DefaultItemTemplate; } } var template = dataTemplate.SelectDataTemplate(item.Element, Shell); return(template); }
public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath) { int section = indexPath.Section; int row = indexPath.Row; var context = Groups[section][row]; DataTemplate template = null; if (context is MenuItem) { template = _context.Shell.MenuItemTemplate ?? DefaultMenuItemTemplate; } else { template = _context.Shell.ItemTemplate ?? DefaultItemTemplate; } var cellId = ((IDataTemplateController)template.SelectDataTemplate(context, _context.Shell)).IdString; var cell = (UIContainerCell)tableView.DequeueReusableCell(cellId); if (cell == null) { var view = (View)template.CreateContent(context, _context.Shell); view.Parent = _context.Shell; cell = new UIContainerCell(cellId, view); cell.BindingContext = context; } else { cell.BindingContext = context; } return(cell); }
public void Bind(object itemBindingContext, ItemsView itemsView, Action <Size> reportMeasure = null, Size?size = null) { var template = _template.SelectDataTemplate(itemBindingContext, itemsView); var templateChanging = template != _selectedTemplate; if (templateChanging) { // Clean up any content we're still holding on to _itemContentView.Recycle(); // Create the new content View = (View)template.CreateContent(); // Set the binding context _before_ we create the renderer; that way, the bound data will be // available during OnElementChanged View.BindingContext = itemBindingContext; // Actually create the native renderer _itemContentView.RealizeContent(View); _selectedTemplate = template; } _itemContentView.HandleItemSizingStrategy(reportMeasure, size); if (!templateChanging) { // Same template, new data View.BindingContext = itemBindingContext; } itemsView.AddLogicalChild(View); }
public void Bind(DataTemplate template, object bindingContext, ItemsView itemsView) { var oldElement = VisualElementRenderer?.Element; // Run this through the extension method in case it's really a DataTemplateSelector var itemTemplate = template.SelectDataTemplate(bindingContext, itemsView); if (itemTemplate != _currentTemplate) { // Remove the old view, if it exists if (oldElement != null) { oldElement.MeasureInvalidated -= MeasureInvalidated; itemsView.RemoveLogicalChild(oldElement); ClearSubviews(); _size = Size.Zero; } // Create the content and renderer for the view var view = itemTemplate.CreateContent() as View; // Prevents the use of default color when there are VisualStateManager with Selected state setting the background color // First we check whether the cell has the default selected background color; if it does, then we should check // to see if the cell content is the VSM to set a selected color if (SelectedBackgroundView.BackgroundColor == ColorExtensions.Gray && IsUsingVSMForSelectionColor(view)) { SelectedBackgroundView = new UIView { BackgroundColor = UIColor.Clear }; } // Set the binding context _before_ we create the renderer; that way, it's available during OnElementChanged view.BindingContext = bindingContext; var renderer = TemplateHelpers.CreateRenderer(view); SetRenderer(renderer); // And make the new Element a "child" of the ItemsView // We deliberately do this _after_ setting the binding context for the new element; // if we do it before, the element briefly inherits the ItemsView's bindingcontext and we // emit a bunch of needless binding errors itemsView.AddLogicalChild(view); } else { // Same template, different data var currentElement = VisualElementRenderer?.Element; if (currentElement != null) { currentElement.BindingContext = bindingContext; } } _currentTemplate = itemTemplate; }
public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath) { int section = indexPath.Section; int row = indexPath.Row; var context = Groups[section][row]; DataTemplate template = ShellController.GetFlyoutItemDataTemplate(context); if (context is IMenuItemController) { if (DefaultMenuItemTemplate != null && _context.Shell.MenuItemTemplate == template) { template = DefaultMenuItemTemplate; } } else { if (DefaultItemTemplate != null && _context.Shell.ItemTemplate == template) { template = DefaultItemTemplate; } } var cellId = ((IDataTemplateController)template.SelectDataTemplate(context, _context.Shell)).IdString; UIContainerCell cell; if (!_cells.TryGetValue(context, out cell)) { var view = (View)template.CreateContent(context, _context.Shell); cell = new UIContainerCell(cellId, view); // Set Parent after binding context so parent binding context doesn't propagate to view cell.BindingContext = context; view.Parent = _context.Shell; } else { var view = _cells[context].View; cell.Disconnect(); cell = new UIContainerCell(cellId, view); cell.BindingContext = context; } cell.SetAccessibilityProperties(context); _cells[context] = cell; cell.TableView = tableView; cell.IndexPath = indexPath; cell.ViewMeasureInvalidated += OnViewMeasureInvalidated; return(cell); }
public void Bind(object itemBindingContext, ItemsView itemsView) { var template = _template.SelectDataTemplate(itemBindingContext, itemsView); View = (View)template.CreateContent(); _itemContentView.RealizeContent(View); // Set the binding context before we add it as a child of the ItemsView; otherwise, it will // inherit the ItemsView's binding context View.BindingContext = itemBindingContext; itemsView.AddLogicalChild(View); }
FrameworkElement RealizeEmptyViewTemplate(object bindingContext, DataTemplate emptyViewTemplate) { if (emptyViewTemplate == null) { return(new TextBlock { Text = bindingContext.ToString() }); } var template = emptyViewTemplate.SelectDataTemplate(bindingContext, null); var view = template.CreateContent() as View; view.BindingContext = bindingContext; return(RealizeEmptyView(view)); }
public void Bind(DataTemplate template, object bindingContext, ItemsView itemsView) { var oldElement = VisualElementRenderer?.Element; // Run this through the extension method in case it's really a DataTemplateSelector var itemTemplate = template.SelectDataTemplate(bindingContext, itemsView); if (itemTemplate != _currentTemplate) { // Remove the old view, if it exists if (oldElement != null) { oldElement.MeasureInvalidated -= MeasureInvalidated; itemsView.RemoveLogicalChild(oldElement); ClearSubviews(); _size = Size.Zero; } // Create the content and renderer for the view var view = itemTemplate.CreateContent() as View; // Set the binding context _before_ we create the renderer; that way, it's available during OnElementChanged view.BindingContext = bindingContext; var renderer = TemplateHelpers.CreateRenderer(view); SetRenderer(renderer); // And make the new Element a "child" of the ItemsView // We deliberately do this _after_ setting the binding context for the new element; // if we do it before, the element briefly inherits the ItemsView's bindingcontext and we // emit a bunch of needless binding errors itemsView.AddLogicalChild(view); } else { // Same template, different data var currentElement = VisualElementRenderer?.Element; if (currentElement != null) { currentElement.BindingContext = bindingContext; } } _currentTemplate = itemTemplate; }
public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath) { int section = indexPath.Section; int row = indexPath.Row; var context = Groups[section][row]; DataTemplate template = ShellController.GetFlyoutItemDataTemplate(context); if (context is IMenuItemController) { if (DefaultMenuItemTemplate != null && _context.Shell.MenuItemTemplate == template) { template = DefaultMenuItemTemplate; } } else { if (DefaultItemTemplate != null && _context.Shell.ItemTemplate == template) { template = DefaultItemTemplate; } } var cellId = ((IDataTemplateController)template.SelectDataTemplate(context, _context.Shell)).IdString; var cell = (UIContainerCell)tableView.DequeueReusableCell(cellId); if (cell == null) { var view = (View)template.CreateContent(context, _context.Shell); cell = new UIContainerCell(cellId, view); // Set Parent after binding context so parent binding context doesn't propagate to view cell.BindingContext = context; view.Parent = _context.Shell; } else { cell.BindingContext = context; } cell.SetAccessibilityProperties(context); _views[context] = cell.View; return(cell); }
FrameworkElement RealizeEmptyViewTemplate(object bindingContext, DataTemplate emptyViewTemplate) { if (emptyViewTemplate == null) { return(new TextBlock { HorizontalAlignment = Microsoft.UI.Xaml.HorizontalAlignment.Center, VerticalAlignment = Microsoft.UI.Xaml.VerticalAlignment.Center, Text = bindingContext.ToString() }); } var template = emptyViewTemplate.SelectDataTemplate(bindingContext, null); var view = template.CreateContent() as View; view.BindingContext = bindingContext; return(RealizeEmptyView(view)); }
public void Bind(object itemBindingContext, ItemsView itemsView, Action <Size> reportMeasure = null, Size?size = null) { var template = _template.SelectDataTemplate(itemBindingContext, itemsView); if (template != _selectedTemplate) { _itemContentView.Recycle(); View = (View)template.CreateContent(); _itemContentView.RealizeContent(View); _selectedTemplate = template; } _itemContentView.HandleItemSizingStrategy(reportMeasure, size); // Set the binding context before we add it as a child of the ItemsView; otherwise, it will // inherit the ItemsView's binding context View.BindingContext = itemBindingContext; itemsView.AddLogicalChild(View); }
public static (UIView NativeView, VisualElement FormsElement) RealizeView(object view, DataTemplate viewTemplate, ItemsView itemsView) { if (viewTemplate != null) { // Run this through the extension method in case it's really a DataTemplateSelector viewTemplate = viewTemplate.SelectDataTemplate(view, itemsView); // We have a template; turn it into a Forms view var templateElement = viewTemplate.CreateContent() as View; // Make sure the Visual property is available when the renderer is created PropertyPropagationExtensions.PropagatePropertyChanged(null, templateElement, itemsView); var renderer = GetHandler(templateElement, itemsView.FindMauiContext()); var element = renderer.VirtualView as VisualElement; // and set the view as its BindingContext element.BindingContext = view; return((UIView)renderer.NativeView, element); } if (view is View formsView) { // Make sure the Visual property is available when the renderer is created PropertyPropagationExtensions.PropagatePropertyChanged(null, formsView, itemsView); // No template, and the EmptyView is a Forms view; use that var renderer = GetHandler(formsView, itemsView.FindMauiContext()); var element = renderer.VirtualView as VisualElement; return((UIView)renderer.NativeView, element); } return(new UILabel { TextAlignment = UITextAlignment.Center, Text = $"{view}" }, null); }
public static object CreateContent(this DataTemplate self, object item, BindableObject container) { return(self.SelectDataTemplate(item, container).CreateContent()); }