Example #1
0
        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));
        }
Example #2
0
        public void ItemTemplateSelectorIsSet()
        {
            var layout = new StackLayout
            {
                IsPlatformEnabled = true,
            };

            var itemsSource = new ObservableCollection <int>(Enumerable.Range(0, 10));

            BindableLayout.SetItemsSource(layout, itemsSource);
            BindableLayout.SetItemTemplateSelector(layout, new DataTemplateSelectorFrame());

            Assert.IsTrue(IsLayoutWithItemsSource(itemsSource, layout));
            Assert.AreEqual(itemsSource.Count, layout.Children.Cast <Frame>().Count());
        }
        public void ItemTemplateTakesPrecendenceOverItemTemplateSelector()
        {
            var layout = new StackLayout
            {
                IsPlatformEnabled = true,
                Platform          = new UnitPlatform()
            };

            var itemsSource = new ObservableCollection <int>(Enumerable.Range(0, 10));

            BindableLayout.SetItemsSource(layout, itemsSource);
            BindableLayout.SetItemTemplate(layout, new DataTemplateBoxView());
            BindableLayout.SetItemTemplateSelector(layout, new DataTemplateSelectorFrame());

            Assert.IsTrue(IsLayoutWithItemsSource(itemsSource, layout));
            Assert.AreEqual(itemsSource.Count, layout.Children.Cast <BoxView>().Count());
        }
Example #4
0
        public void ContainerIsPassedInSelectTemplate()
        {
            var layout = new StackLayout
            {
                IsPlatformEnabled = true,
            };

            var itemsSource = new ObservableCollection <int>(Enumerable.Range(0, 10));

            BindableLayout.SetItemsSource(layout, itemsSource);

            int containerPassedCount = 0;

            BindableLayout.SetItemTemplateSelector(layout, new MyDataTemplateSelectorTest((item, container) =>
            {
                if (container == layout)
                {
                    ++containerPassedCount;
                }
                return(null);
            }));

            Assert.AreEqual(containerPassedCount, itemsSource.Count);
        }
 public static TLayout ItemTemplateSelector <TLayout>(this TLayout layout, DataTemplateSelector selector) where TLayout : Layout <View>
 {
     BindableLayout.SetItemTemplateSelector(layout, selector); return(layout);
 }
 public static T SetDataTemplateSelector <T>(this T bindable, DataTemplateSelector dataTemplateSelector) where T : BindableObject
 {
     BindableLayout.SetItemTemplateSelector(bindable, dataTemplateSelector);
     return(bindable);
 }
 public static T BindItemTemplateSelector <T>(this T layout, DataTemplateSelector selector) where T : Layout
 {
     BindableLayout.SetItemTemplateSelector(layout, selector);
     return(layout);
 }