0

我在当前代码中面临一个问题。

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

XAML 看起来像这样。

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

...... <\网格>

注册的依赖属性看起来像这样

public static readonly DependencyProperty buttonDisplay= DependencyProperty.Register("showbutton", typeof(bool), typeof(class2), new PropertyMetadata((bool)false));

public bool showbutton
{
    get { return (bool)GetValue(buttonDisplay); }
    set { SetValue(buttonDisplay, value); }
}

更新被称为直通

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

该按钮未根据 showbutton 启用。可能是什么问题?是否可以以编程方式更改 showbutton 值。如果有怎么办?

4

1 回答 1

1

试试这个 DataContext.class1.class2.showbutton - 确保绑定路径是正确的。您可以使用名为 snoop 的实用程序检查绑定错误。 http://snoopwpf.codeplex.com/

于 2013-02-22T01:51:39.010 回答