1
votes

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

1 Answers

2
votes

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