在上一个问题中,kbmax 告诉我如何在我的 generic.xaml 中绑定自定义属性。这个答案是在Setting Border background with a template binding
在我尝试使用 LinearGradientBrush StartPoint 之前,它工作得很好,这是一个示例:
这显然工作正常:
<LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
我想将它们绑定到这样的自定义属性:这不起作用,无论我将属性设置为什么,我总是得到一个从左到右的渐变。
<LinearGradientBrush StartPoint="{Binding HeaderBorderGradientStartPoint, RelativeSource={RelativeSource TemplatedParent}}" EndPoint="{Binding HeaderBorderGradientEndPoint, RelativeSource={RelativeSource TemplatedParent}}">
这是类中的代码。
public static readonly DependencyProperty HeaderBorderGradientStartPointProperty =
DependencyProperty.Register("HeaderBorderGradientStartPoint", typeof(Point), typeof(GalleryExpander), new PropertyMetadata(new Point(0.5,0)));
public Point HeaderBorderGradientStartPoint {
get { return (Point)GetValue(HeaderBorderGradientStartPointProperty); }
set { SetValue(HeaderBorderGradientStartPointProperty, value); }
}
public static readonly DependencyProperty HeaderBorderGradientEndPointProperty =
DependencyProperty.Register("HeaderBorderGradientEndPoint", typeof(Point), typeof(GalleryExpander), new PropertyMetadata(new Point(0.5,1)));
public Point HeaderBorderGradientEndPoint {
get { return (Point)GetValue(HeaderBorderGradientEndPointProperty); }
set { SetValue(HeaderBorderGradientEndPointProperty, value); }
}
<Border.BorderBrush>
<LinearGradientBrush StartPoint="{Binding HeaderBorderGradientStartPoint, RelativeSource={RelativeSource TemplatedParent}}" EndPoint="{Binding HeaderBorderGradientEndPoint, RelativeSource={RelativeSource TemplatedParent}}">
<LinearGradientBrush.GradientStops>
<GradientStop Offset="0.0" Color="Transparent" />
<GradientStop Offset="0.25" Color="Transparent" />
<GradientStop Offset="0.50" Color="Transparent" />
<GradientStop Offset="0.75" Color="Transparent" />
<GradientStop Offset="1.0" Color="Transparent" />
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
</Border.BorderBrush>
感谢您的任何指导...