wpf System.Windows.Data 错误:40:BindingExpression 路径错误:在对象上找不到属性

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19228677/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 09:48:09  来源:igfitidea点击:

System.Windows.Data Error: 40 : BindingExpression path error: property not found on object

c#wpfxamldata-binding

提问by Tim

Many apologies to add to the massive list of similar binding error questions out there, but after hours of searching I can't find a solution that will work for me!

许多道歉要添加到大量类似的绑定错误问题列表中,但经过数小时的搜索,我找不到适合我的解决方案!

I am trying to test a ViewModel in WPF, but the ICommand Button code is causing the standard binding error:

我正在尝试在 WPF 中测试 ViewModel,但 ICommand 按钮代码导致标准绑定错误:

System.Windows.Data Error: 40 : BindingExpression path error: 'CheckforNewHubs' property not found on 'object' ''HubManagerViewModel' (HashCode=13328197)'. BindingExpression:Path=CheckforNewHubs; DataItem='HubManagerViewModel' (HashCode=13328197); target element is 'Button' (Name='CheckForNewHubsButton'); target property is 'Command' (type 'ICommand')

System.Windows.Data 错误:40:BindingExpression 路径错误:在“对象”“HubManagerViewModel”(HashCode=13328197)上找不到“CheckforNewHubs”属性。BindingExpression:Path=CheckforNewHubs; DataItem='HubManagerViewModel' (HashCode=13328197); 目标元素是 'Button' (Name='CheckForNewHubsButton'); 目标属性是“命令”(类型“ICommand”)

my command (in HubManagerViewModel) is:

我的命令(在 HubManagerViewModel 中)是:

public ICommand CheckForNewHubs
{
    get
    {
        return new RelayCommand(this.CheckForNewHubsExecute, this.CanSendHubManagerCommands);
    }
    set { }
}

and my DataContext is initiated in an XAML grid as:

并且我的 DataContext 在 XAML 网格中启动为:

<Grid.DataContext>
    <ViewModels:HubManagerViewModel/>
</Grid.DataContext>

I have tried explicitly setting the dataContext of the button like this:

我尝试过像这样显式设置按钮的 dataContext:

<Button.DataContext>
    <ViewModels:HubManagerViewModel/>
</Button.DataContext>

Can anyone tell me what I'm doing wrong? At this point I'm just desperate for some new insight.

谁能告诉我我做错了什么?在这一点上,我只是迫切需要一些新的见解。

Thanks for your time in advance!

提前感谢您的时间!

回答by LPL

You have used Binding Path CheckforNewHubsbut it should be CheckForNewHubs.

您已经使用了 Binding PathCheckforNewHubs但它应该是CheckForNewHubs.