xamarin 错误XFC0009找不到“LeftSetsValue”的属性、BindableProperty或事件,或者值和属性之间的类型不匹配

c86crjj0  于 2023-01-06  发布在  其他
关注(0)|答案(1)|浏览(140)

我正在使用MAUI应用程序。我创建了一个内容视图作为自定义控件。该内容视图有2个条目控件。我想从内容页面绑定这些条目。我执行了以下代码,但收到错误。

public static readonly BindableProperty LeftSetsProperty = BindableProperty.Create(nameof(LeftSetsValue), typeof(string), typeof(ExerciseSelection), string.Empty, defaultBindingMode: BindingMode.TwoWay);
    
public string LeftSetsValue
{
    get => (string)GetValue(LeftSetsProperty);
    set => SetValue(LeftSetsProperty, value);
}
<Entry Grid.Row="0" Grid.Column="1" VerticalOptions="End" HorizontalTextAlignment="Center" MaxLength="3" TextColor="Black" Keyboard="Numeric" Text="{Binding LeftSetsValue, Source={x:Reference exerciseSelectionControl}}" />

在内容页中,我使用此控件的方式如下

<controls:ExerciseSelection Grid.Row="0" Margin="0,0,90,0" ExerciseName="EMPTY CAN" ClassId="emptycan" ExerciseClicked="ExerciseButton_Clicked" LeftSetsValue="{Binding SharedVM.LeftSetForExptyCan}"/>

在ViewModel中,我创建了如下属性:

private string _leftSetForExptyCan;
    public string LeftSetForExptyCan
    {
        get => _leftSetForExptyCan;
        set
        {
            if (_leftSetForExptyCan != value)
            {
                _leftSetForExptyCan = value;
                OnPropertyChanged(nameof(LeftSetForExptyCan));
            }
        }
    }

我收到以下错误。我找不到问题所在。
严重性代码说明项目文件行隐藏状态错误XFC0009找不到"LeftSetsValue"的属性、BindableProperty或事件,或者值和属性之间的类型不匹配。...\Pages\HomePage. xaml 60

cgyqldqp

cgyqldqp1#

您必须将BindableProperty名称更改为"LeftSetsValueProperty":

public static readonly BindableProperty LeftSetsValueProperty = ...

该文件规定:

    • 重要**

可绑定属性的命名约定是,可绑定属性标识符必须与Create方法中指定的属性名称匹配,并在其后面追加"Property"。

相关问题