简体   繁体   English

绑定不起作用 - 没有属性、可绑定属性或事件发现错误

[英]Binding doesn't work - No property, bindable property, or event found error

Am having an issue with binding, but I first searched with several questions on this, but no luck, below is the error am getting :我遇到了绑定问题,但我首先搜索了几个关于此的问题,但没有运气,下面是错误:

Error: Position 18:36.错误:位置 18:36。 No property, bindable property, or event found for 'Lat', or mismatching type between value and property找不到“纬度”的属性、可绑定属性或事件,或者值和属性之间的类型不匹配

Below is my xaml file :下面是我的xaml文件:

<controls:MapView x:Name="map" VerticalOptions="FillAndExpand">
            <controls:MapView.Center>
                <controls:Position Lat="{Binding latitude}" Long="{Binding longitude}" />
            </controls:MapView.Center>
        </controls:MapView>

Then the c# code is as below :然后c#代码如下:

public partial class DisplayMap : ContentPage
    {

        private double latitude { get; } 
        private double longitude { get; } 

        public DisplayMap()
        {

            InitializeComponent();

            this.latitude = 0.3476;
            this.longitude = 32.5825;

            BindingContext = this;

        }

What am I missing ?我错过了什么?

The issue seems to be a lack of publicly-accessible bindable properties in the Position class (notice that the error mentions Lat which is a member of Position ).问题似乎是Position类中缺少可公开访问的可绑定属性(请注意,错误提到LatPosition的成员)。 Position should look something like this: Position应如下所示:

public class Position : BindableObject
{
    public static readonly BindableProperty LatProperty = BindableProperty.Create(nameof(Lat), typeof(double), typeof(Position), 0);
    public double Lat
    {
        get { return (double)this.GetValue(LatProperty); }
        set { this.SetValue(LatProperty, value); }
    } 

    public static readonly BindableProperty LongProperty = BindableProperty.Create(nameof(Long), typeof(double), typeof(Position), 0);
    public double Long
    {
        get { return (double)this.GetValue(LongProperty); }
        set { this.SetValue(LongProperty, value); }
    }

    // ...

I suggest you take a look at the official documentation for Bindable Properties .我建议您查看Bindable Properties官方文档 Essentially, the error message you are getting is because it is looking for LatProperty when trying to bind using the accessor Lat .本质上,您收到的错误消息是因为它在尝试使用访问器Lat进行绑定时正在寻找LatProperty

The reason why you are not able to use the Lat and Long property is that if you check the Position class there is no Bindable Property defined for them in it which means you cannot access them in XAML,您无法使用 Lat 和 Long 属性的原因是,如果您检查Position类,则其中没有为它们定义的 Bindable 属性,这意味着您无法在 XAML 中访问它们,

A possible solution is to download the Sample project and take the code and make the respective changes for it to have Bindable Properties.一种可能的解决方案是下载示例项目并获取代码并对其进行相应更改以使其具有可绑定属性。

For that, you can check @Aaron's answer为此,您可以查看@Aaron 的答案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Xamarin Forms 4.11.0错误:找不到UWP的属性,可绑定属性或事件 - Xamarin Forms 4.11.0 error: No property, bindable property or event found for UWP Xamarin没有找到'ToolbarItems'的属性,可绑定属性或事件 - Xamarin No property, bindable property, or event found for 'ToolbarItems' 绑定不适用于 xamarin 形式的 MVVM。 未找到“ItemSelected”的属性、可绑定属性或事件, - Binding not working with MVVM in xamarin form. No property, bindable property, or event found for 'ItemSelected', 绑定到属性不起作用 - Binding to a property doesn't work 暴露的可绑定属性未正确绑定 - Exposed Bindable Property not binding correctly 绑定到依赖属性不起作用 - Binding to a depencency property doesn't work 绑定到UserControl的属性不起作用 - Binding to property of UserControl doesn't work 没有找到“ItemsSource”的属性、可绑定属性或事件,或者值和属性之间的类型不匹配? - No property, bindable property, or event found for 'ItemsSource', or mismatching type between value and property? 找不到“已加载”的属性,可绑定属性或事件,或值和属性之间的类型不匹配 - No property, bindable property, or event found for 'Loaded', or mismatching type between value and property 自定义控件可绑定属性不适用于 ViewModel - Custom control Bindable property don't work with ViewModel
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM