帮助WPF绑定

时间:2010-11-18 16:21:05

标签: wpf data-binding binding

我需要将自定义依赖项属性绑定到控件内的Image元素。

现在Label的{​​{1}}与Foreground绑定得非常好,但TextForeground内的GeometryDrawing绑定得很好(图片保持透明)。< / p>

有什么问题?

Image

2 个答案:

答案 0 :(得分:3)

GeometryDrawing没有TextForeground属性。您正在引用Self,即GeometryDrawing。如果您尝试从其他控件中抓取RelativeSource,请更改TextForeground

<GeometryDrawing.Pen>
    <Pen Brush="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=TextForeground}" Thickness="1"/>
</GeometryDrawing.Pen>

答案 1 :(得分:3)

<UserControl x:Name="MyStopControl" >
    ...
    <Pen Brush="{Binding ElementName=MyStopControl, Path=TextForeground}"/>
    ...
</UserControl>