user1687824
user1687824

Reputation: 807

Databinding-dependency property with Relativesource

I am facing a issue in the present code.

The UI has a button, which is databound to a dependency property showbutton. Its built on the MVVM architecture.

The XAML looks like this.

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

............... <\Grid>

The registered dependencyproperty looks like this

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); }
}

The update is called thru

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

the button is not getting enabled according to the showbutton. What can be the problem ? Is it possible to change showbutton value programatically . If so how ?

Upvotes: 0

Views: 131

Answers (1)

Liju
Liju

Reputation: 91

Try this DataContext.class1.class2.showbutton - Ensure that the binding path is correct. You can check for binding errors using a utility called snoop. http://snoopwpf.codeplex.com/

Upvotes: 1

Related Questions