public void ItemTemplateFunction() { Func <object> loadTemplate = () => new BoxView(); Bindable.ItemTemplate(loadTemplate); Assert.That(BindableLayout.GetItemTemplate(Bindable), Is.Not.Null); }
public void ValidateBindableProperties() { var layout = new StackLayout { IsPlatformEnabled = true, }; // EmptyView object emptyView = new object(); BindableLayout.SetEmptyView(layout, emptyView); Assert.AreEqual(emptyView, BindableLayout.GetEmptyView(layout)); Assert.AreEqual(emptyView, layout.GetValue(BindableLayout.EmptyViewProperty)); // EmptyViewTemplateProperty DataTemplate emptyViewTemplate = new DataTemplate(typeof(Label)); BindableLayout.SetEmptyViewTemplate(layout, emptyViewTemplate); Assert.AreEqual(emptyViewTemplate, BindableLayout.GetEmptyViewTemplate(layout)); Assert.AreEqual(emptyViewTemplate, layout.GetValue(BindableLayout.EmptyViewTemplateProperty)); // ItemsSourceProperty IEnumerable itemsSource = new object[0]; BindableLayout.SetItemsSource(layout, itemsSource); Assert.AreEqual(itemsSource, BindableLayout.GetItemsSource(layout)); Assert.AreEqual(itemsSource, layout.GetValue(BindableLayout.ItemsSourceProperty)); // ItemTemplateProperty DataTemplate itemTemplate = new DataTemplate(typeof(Label)); BindableLayout.SetItemTemplate(layout, itemTemplate); Assert.AreEqual(itemTemplate, BindableLayout.GetItemTemplate(layout)); Assert.AreEqual(itemTemplate, layout.GetValue(BindableLayout.ItemTemplateProperty)); // ItemTemplateSelectorProperty var itemTemplateSelector = new DataTemplateSelectorFrame(); BindableLayout.SetItemTemplateSelector(layout, itemTemplateSelector); Assert.AreEqual(itemTemplateSelector, BindableLayout.GetItemTemplateSelector(layout)); Assert.AreEqual(itemTemplateSelector, layout.GetValue(BindableLayout.ItemTemplateSelectorProperty)); }
// Checks if for every item in the items source there's a corresponding view static bool IsLayoutWithItemsSource(IEnumerable itemsSource, Compatibility.Layout layout) { if (itemsSource == null) { return(layout.Children.Count() == 0); } int i = 0; foreach (object item in itemsSource) { if (BindableLayout.GetItemTemplate(layout) is DataTemplate dataTemplate || BindableLayout.GetItemTemplateSelector(layout) is DataTemplateSelector dataTemplateSelector) { if (!Equals(item, layout.Children[i].BindingContext)) { return(false); } }