I'm having a bit of a problem with Xamarin Data Binding. When binding to an item in a C# class, I get the error seen in the title. I've been trying to bind an element from the table example found here. I tried adding BindingContext = this;
to the constructor and to change the line above the class declaration to [DesignTimeVisible(false)]
the way it is in the NewItemPage
from the Master-Detail template found during the creation of the project, however, it did not help.
Here is the code:
XAML:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="NetworkScanner.Views.TestPage">
<TableView>
<TableRoot>
<TableSection Title="Getting Started" BindingContext="{x:Reference Table}">
<ViewCell>
<StackLayout Orientation="Horizontal">
<Image Source="bulb.png" />
<Label Text="left"
TextColor="#f35e20" />
<Label Text="right"
HorizontalOptions="EndAndExpand"
TextColor="#503026" />
</StackLayout>
</ViewCell>
</TableSection>
</TableRoot>
</TableView>
</ContentPage>
C#:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Xamarin.Forms; using Xamarin.Forms.Xaml; namespace NetworkScanner.Views { [XamlCompilation(XamlCompilationOptions.Compile)] // [DesignTimeVisible(false)] public partial class TestPage : ContentPage { public TableSection Table { get; set; } public TestPage() { InitializeComponent(); // BindingContext = this; } } }
Table
property. Generally if you want a table that is data driven you would use a ListView or CollectionVIew, not a TableView. – Jason