public int FrameThickness
{
get { return (int)GetValue(FrameThicknessProperty); }
set { SetValue(FrameThicknessProperty, value); }
}
public static readonly DependencyProperty FrameThicknessProperty =
DependencyProperty.Register(nameof(FrameThickness), typeof(int), typeof(RectZone), new PropertyMetadata(1));
public string Title
{
get { return (string)GetValue(TitleProperty); }
set { SetValue(TitleProperty, value); }
}
public static readonly DependencyProperty TitleProperty =
DependencyProperty.Register(nameof(Title), typeof(string), typeof(RectZone), new PropertyMetadata("title"));
public ImageBrush? ZoneImage
{
get { return (ImageBrush)GetValue(ZoneImageProperty); }
set { SetValue(ZoneImageProperty, value); }
}
public static readonly DependencyProperty ZoneImageProperty =
DependencyProperty.Register(nameof(ZoneImage), typeof(ImageBrush), typeof(RectZone), new PropertyMetadata(null));
public Visibility LogVisibility
{
get { return (Visibility)GetValue(LogVisibilityProperty); }
set { SetValue(LogVisibilityProperty, value); }
}
public static readonly DependencyProperty LogVisibilityProperty =
DependencyProperty.Register(nameof(LogVisibility), typeof(Visibility), typeof(RectZone), new PropertyMetadata(Visibility.Visible));
Я считаю, что все это правильно, у дизайнера VS2022 проблем нет, тем не менее, я получаю ошибки привязки XAML:
Severity: Error
Count: 4
Data Context: Visibility
Binding Path: TitleVisibility
Target: RectZone.TitleVisibility
Target Type: Visibility
Description File: TitleVisibility property not found on object of type Visibility
Итак:
что не так в моем коде?
Я думал, что RelativeSource={RelativeSource AncestorType=control:RectZone полностью определит контекст данных, но ошибки привязки показывают, что это не так: почему?
если не то я делаю неправильно с точки зрения контекста данных?
В проекте WPF у меня есть UserControl под названием RectZone , который начинается с [code]
[/code] В коде определены зависимости свойств: [code]public int FrameThickness { get { return (int)GetValue(FrameThicknessProperty); } set { SetValue(FrameThicknessProperty, value); } }
public static readonly DependencyProperty FrameThicknessProperty = DependencyProperty.Register(nameof(FrameThickness), typeof(int), typeof(RectZone), new PropertyMetadata(1));
public string Title { get { return (string)GetValue(TitleProperty); } set { SetValue(TitleProperty, value); } }
public static readonly DependencyProperty TitleProperty = DependencyProperty.Register(nameof(Title), typeof(string), typeof(RectZone), new PropertyMetadata("title"));
public ImageBrush? ZoneImage { get { return (ImageBrush)GetValue(ZoneImageProperty); } set { SetValue(ZoneImageProperty, value); } }
public static readonly DependencyProperty ZoneImageProperty = DependencyProperty.Register(nameof(ZoneImage), typeof(ImageBrush), typeof(RectZone), new PropertyMetadata(null));
public Visibility LogVisibility { get { return (Visibility)GetValue(LogVisibilityProperty); } set { SetValue(LogVisibilityProperty, value); } }
public static readonly DependencyProperty LogVisibilityProperty = DependencyProperty.Register(nameof(LogVisibility), typeof(Visibility), typeof(RectZone), new PropertyMetadata(Visibility.Visible)); [/code] Я считаю, что все это правильно, у дизайнера VS2022 проблем нет, тем не менее, я получаю ошибки привязки XAML: [img]https://i.sstatic.net/gmTY7jIz.png[/img]
текстовая версия для одного из них: [code]Severity: Error Count: 4 Data Context: Visibility Binding Path: TitleVisibility Target: RectZone.TitleVisibility Target Type: Visibility Description File: TitleVisibility property not found on object of type Visibility [/code] Итак: [list] [*]что не так в моем коде? [*]Я думал, что RelativeSource={RelativeSource AncestorType=control:RectZone полностью определит контекст данных, но ошибки привязки показывают, что это не так: почему? [*]если не то я делаю неправильно с точки зрения контекста данных? [/list]