1

I created a UserControl in WPF and generated some Dependency Properties. But on one of the Properties i cannot set a Binding in XAML.

internal Visibility ProgressbarVisibility { get { return (Visibility)GetValue(ProgressbarVisibilityProperty); } set { SetValue(ProgressbarVisibilityProperty, value); } } internal static readonly DependencyProperty ProgressbarVisibilityProperty = DependencyProperty.Register("ProgressbarVisibility", typeof(Visibility), typeof(ImportBox), new PropertyMetadata(Visibility.Hidden)); 

So i get the following Error:

A 'Binding' cannot be set on the 'ProgressbarVisibility' property of type 'ImportBox'. A 'Binding' can only be set on a DependencyProperty of a DependencyObject.

When i set the Property "hardcoded" with a fix Value, its no Problem.

The other Dependeny Properties dont throw Errors of this type and i can Bind everthing i want.

internal ImageSource ImageSource { get { return (ImageSource)GetValue(ImageSourceProperty); } set { SetValue(ImageSourceProperty, value); } } internal static readonly DependencyProperty ImageSourceProperty = DependencyProperty.Register("ImageSource", typeof(ImageSource), typeof(ImportBox)); internal string HeaderText { get { return (string)GetValue(HeaderTextProperty); } set { SetValue(HeaderTextProperty, value); } } internal static readonly DependencyProperty HeaderTextProperty = DependencyProperty.Register("HeaderText", typeof(string), typeof(ImportBox)); internal UIElement PresenterContent { get { return (UIElement)GetValue(PresenterContentProperty); } set { SetValue(PresenterContentProperty, value); } } internal static readonly DependencyProperty PresenterContentProperty = DependencyProperty.Register("PresenterContent", typeof(UIElement), typeof(ImportBox)); 

1 Answer 1

2

Make the DependencyProperty as Public will solves your problem...

public Visibility ProgressbarVisibility { get { return (Visibility)GetValue(ProgressbarVisibilityProperty); } set { SetValue(ProgressbarVisibilityProperty, value); } } public static readonly DependencyProperty ProgressbarVisibilityProperty = DependencyProperty.Register("ProgressbarVisibility", typeof(Visibility), typeof(ImportBox), new PropertyMetadata(Visibility.Hidden)); 
Sign up to request clarification or add additional context in comments.

1 Comment

Okay... thanks! Second Problem was, that i set the Properties in Datacontext also internal. Now its works.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.