我收到此错误:
Cannot find source for binding with reference 'RelativeSource FindAncestor,
AncestorType='System.Windows.Controls.UserControl', AncestorLevel='1''
关于此绑定:
<DataGridTemplateColumn Visibility="{Binding DataContext.IsVisible,
RelativeSource={RelativeSource AncestorType={x:Type UserControl}},
Converter={StaticResource BooleanToVisibilityConverter}}">
The ViewModel
正坐着DataContext
in UserControl
. The DataContext
of the DataGrid
(坐在UserControl
) 是以下范围内的财产ViewModel
, in ViewModel
我有一个变量表示是否显示某一行,它的绑定失败,为什么?
这是我的财产:
private bool _isVisible=false;
public bool IsVisible
{
get { return _isVisible; }
set
{
_isVisible= value;
NotifyPropertyChanged("IsVisible");
}
}
说到功能:NotifyPropertyChanged
the PropertyChanged
事件 null - 意味着他未能注册绑定。
应该注意的是,我有更多的绑定ViewModel
以这种有效的方式,这里是一个例子:
Command="{Binding DataContext.Cmd,
RelativeSource={RelativeSource AncestorType={x:Type UserControl}}}"