如何使依赖对象属性的数组可绑定,以便稍后作为静态资源进行绑定?
我现在拥有的代码似乎绕过了依赖属性系统...
我有以下类:
在XAML中,我创建了一个包含这些资源数组的绑定。
在调试绑定时,我注意到如果我删除DP的setter,则XAML将显示一个错误,说这个属性丢失了。我的理解是,XAML使用DP系统来分配值,从而实现绑定。在这种情况下,如果XAML期望一个“普通”的属性,绑定是不可能的。有谁能告诉我如何使它正常工作?
我现在拥有的代码似乎绕过了依赖属性系统...
我有以下类:
public class ValueMarker : DependencyObject
{
public static readonly DependencyProperty BrushProperty = DependencyProperty.Register("Brush", typeof(Brush), typeof(ValueMarker), new FrameworkPropertyMetadata(Brushes.Aqua));
public static readonly DependencyProperty ValueProperty = DependencyProperty.Register("Value", typeof(double), typeof(ValueMarker), new FrameworkPropertyMetadata(0d));
public static readonly DependencyProperty OffsetProperty = DependencyProperty.Register("Offset", typeof(double), typeof(ValueMarker), new FrameworkPropertyMetadata(0d));
public Brush Brush
{
get { return (Brush)GetValue(BrushProperty); }
set { SetValue(BrushProperty, value); }
}
public double Offset
{
get { return (double)GetValue(OffsetProperty); }
set { SetValue(OffsetProperty, value); }
}
public double Value
{
get { return (double)GetValue(ValueProperty); }
set { SetValue(ValueProperty, value); }
}
}
在XAML中,我创建了一个包含这些资源数组的绑定。
<x:Array Type="my:ValueMarker" x:Key="plainMarks">
<my:ValueMarker Brush="Red" Offset="-5" Value="{Binding Path=...}" />
<my:ValueMarker Brush="Orange" Offset="-5" Value="{Binding Path=...}"/>
<my:ValueMarker Brush="Orange" Offset="-5" Value="{Binding Path=...}"/>
<my:ValueMarker Brush="Red" Offset="-5" Value="{Binding Path=...}" />
</x:Array>
在调试绑定时,我注意到如果我删除DP的setter,则XAML将显示一个错误,说这个属性丢失了。我的理解是,XAML使用DP系统来分配值,从而实现绑定。在这种情况下,如果XAML期望一个“普通”的属性,绑定是不可能的。有谁能告诉我如何使它正常工作?