You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

MAUI自定义控件绑定报错XFC0009:找不到LeftSetsValue属性

MAUI自定义控件绑定错误XFC0009解决方法

核心问题:BindableProperty命名不符合规范

你的自定义控件中,可绑定属性的命名违反了MAUI的约定:属性对应的BindableProperty必须命名为「属性名+Property」。当前属性是LeftSetsValue,但BindableProperty命名为LeftSetsProperty,缺少Value后缀,导致XAML解析时无法匹配到对应的可绑定属性,触发XFC0009错误。

修正代码

将自定义控件中的BindableProperty定义修改为:

public static readonly BindableProperty LeftSetsValueProperty = BindableProperty.Create(
    nameof(LeftSetsValue), 
    typeof(string), 
    typeof(ExerciseSelection), 
    string.Empty, 
    defaultBindingMode: BindingMode.TwoWay);

public string LeftSetsValue
{
    get => (string)GetValue(LeftSetsValueProperty);
    set => SetValue(LeftSetsValueProperty, value);
}

额外检查项

如果修正后仍报错,排查以下几点:

  • 自定义控件类访问权限:确保ExerciseSelection类是public修饰的,否则ContentPage无法正确识别该控件的属性。
  • XAML命名空间引用:确认ContentPage的XAML头部已正确引用自定义控件所在的命名空间,示例:
    xmlns:controls="clr-namespace:YourAppName.Controls"
    
    替换YourAppName.Controls为实际的命名空间路径。
  • ViewModel属性拼写:你绑定的SharedVM.LeftSetForExptyCan中Expty是Empty的笔误,虽不会导致编译错误,但运行时可能出现绑定失效,建议修正为LeftSetForEmptyCan并同步ViewModel中的属性名。

内容的提问来源于stack exchange,提问作者RMR

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.15 11:05:22