0

I have a user control that is having issues binding to a dependency property for IsEnabled. I have also tried manually setting the IsEnabled="false" and that also appears to be not working.

Here is the code:

public partial class News : UserControl { public static readonly DependencyProperty IsAuthenticatedProperty = DependencyProperty.Register( "IsAuthenticated", typeof(bool), typeof(News), new FrameworkPropertyMetadata( new PropertyChangedCallback(ChangeAuth))); public bool IsAuthenticated { get { return (bool) GetValue(IsAuthenticatedProperty); } set { SetValue(IsAuthenticatedProperty, value); } } private static void ChangeAuth(DependencyObject source, DependencyPropertyChangedEventArgs e) { if (e.NewValue is bool == false) { (source as News).UpdateAuth(false); } else { (source as News).UpdateAuth(true); } } private void UpdateAuth(bool value) { IsAuthenticated = value; } public News() { IsAuthenticated = false; this.IsEnabled = false; InitializeComponent(); } 

Any Ideas ? Thanks In Advance

1 Answer 1

1

It's hard to be certain since you haven't shown your binding in XAML, however, your binding will by default be looking for the bound property on whatever is set in the DataContext. I suspect this is the problem...

If this assumption is correct, a similar solution is presented over here...

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.