C# 使用Relativesource绑定依赖项属性

C# 使用Relativesource绑定依赖项属性,c#,wpf,data-binding,user-interface,mvvm,C#,Wpf,Data Binding,User Interface,Mvvm,我在目前的准则中面临一个问题 UI有一个按钮,该按钮与依赖项属性showbutton进行数据绑定。它建立在MVVM架构之上 XAML看起来像这样 <Grid> ......... <Button .... IsEnabled="{Binding Path=class1.class2.showbutton,RelativeSource={RelativeSource FindAncestor, AncestorType=views:view2, Mode=FindAncestor

我在目前的准则中面临一个问题

UI有一个按钮,该按钮与依赖项属性showbutton进行数据绑定。它建立在MVVM架构之上

XAML看起来像这样

<Grid>
.........
<Button .... IsEnabled="{Binding Path=class1.class2.showbutton,RelativeSource={RelativeSource FindAncestor, AncestorType=views:view2, Mode=FindAncestor, AncestorLevel=1}}"/>
更新被称为thru

private void UpdateProperties()
 {
   showbutton= User.CheckPrivilege("ShudEnable");        }
 }

未根据showbutton启用该按钮。有什么问题吗?是否可以通过编程更改showbutton值。如果是,如何操作?

尝试此DataContext.class1.class2.showbutton-确保绑定路径正确。可以使用名为snoop的实用程序检查绑定错误。

能否显示您的ViewModel代码?嗯。。它相当复杂和巨大。它有嵌套的视图模型,这些模型是从viewmodel库中派生出来的。你到底需要什么?showbutton程序代码。我又添加了一个func!有吗?
private void UpdateProperties()
 {
   showbutton= User.CheckPrivilege("ShudEnable");        }
 }