我在WPF中创建了一个UserControl并生成了一些依赖属性。 但是在其中一个属性上我无法在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));
所以我得到以下错误:
无法在'ProgressbarVisibility'属性上设置'绑定' 输入'ImportBox'。 '绑定'只能在DependencyProperty上设置 DependencyObject。
当我使用修复值设置属性“硬编码”时,没有问题。
其他Dependeny属性不会抛出这种类型的错误,我可以绑定我想要的东西。
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));
答案 0 :(得分:2)
让公共DependencyProperty
解决您的问题......
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));