У меня небольшая проблема с привязкой данных Xamarin. При привязке к элементу в классе C# я получаю ошибку, указанную в заголовке. Я пытался привязать элемент из примера таблицы, найденного здесь . Я попытался добавить BindingContext = this;
в конструктор и изменить строку над объявлением класса на [DesignTimeVisible(false)]
, как в NewItemPage
из шаблона Master-Detail, найденного во время создания проекта, однако этого не произошло. help.
Вот код:
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;
}
}
}