0

I need to bind the custom dependency property to the Image elements inside a control.

Now the Label's Foreground binds very well to TextForeground, but not the GeometryDrawing inside the Image (the Image remains Transparent).

What is wrong?

<UserControl x:Class="MyStopControl"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" Height="12" Width="24">
    <Canvas >
        <Image x:Name="Dot" Canvas.Left="0" Canvas.Top="0">
            <Image.Source>
                <DrawingImage>
                    <DrawingImage.Drawing>
                        <DrawingGroup>
                            <GeometryDrawing>
                                <GeometryDrawing.Pen>
                                    <Pen Brush="{Binding RelativeSource={x:Static RelativeSource.Self},Path=TextForeground}" Thickness="2" x:Name="BigCircleThickness"/>
                                </GeometryDrawing.Pen>
                                <GeometryDrawing.Geometry>
                                    <GeometryGroup>
                                        <EllipseGeometry x:Name="BigCircle" Center="0,0" RadiusX="7" RadiusY="7"/>
                                    </GeometryGroup>
                                </GeometryDrawing.Geometry>
                            </GeometryDrawing>
                            <GeometryDrawing>
                                <GeometryDrawing.Pen>
                                    <Pen Brush="{Binding RelativeSource={x:Static RelativeSource.Self},Path=TextForeground}"  Thickness="1"/>
                                </GeometryDrawing.Pen>
                                <GeometryDrawing.Geometry>
                                    <GeometryGroup>
                                        <EllipseGeometry x:Name="MediumCircle" Center="0,0" RadiusX="4" RadiusY="4"/>
                                    </GeometryGroup>
                                </GeometryDrawing.Geometry>
                            </GeometryDrawing>
                            <GeometryDrawing Brush="{Binding RelativeSource={x:Static RelativeSource.Self},Path=TextForeground}">
                                <GeometryDrawing.Geometry>
                                    <GeometryGroup>
                                        <EllipseGeometry x:Name="SmallCircle" Center="0,0" RadiusX="2" RadiusY="2"/>
                                    </GeometryGroup>
                                </GeometryDrawing.Geometry>
                            </GeometryDrawing>
                        </DrawingGroup>
                    </DrawingImage.Drawing>
                </DrawingImage>
            </Image.Source>
        </Image>

        <Border x:Name="StopShadow"
                Background="{Binding ElementName=TextBackground}" 
                LayoutTransform="{Binding ElementName=StopText, Path=LayoutTransform}">
            <Label x:Name="StopLabel" 
                   Content="Bla bla some text" 
                   Foreground="{Binding ElementName=TextForeground}" />
        </Border>

    </Canvas>
</UserControl>

2 Answers 2

3

GeometryDrawing does not have a TextForeground property. You are referencing Self, which would be the GeometryDrawing. Change your RelativeSource if you are trying to grab the TextForeground from a different Control.

<GeometryDrawing.Pen>
    <Pen Brush="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=TextForeground}" Thickness="1"/>
</GeometryDrawing.Pen>
Sign up to request clarification or add additional context in comments.

4 Comments

MyStopControl has the TextForeground property. So by e.g. for the Label > Foreground="{Binding ElementName=TextForeground}" works wery well.
@serhio You are referencing RelativeSource={x:Static RelativeSource.Self} on the GeometryDrawing though...in the Label you are not
so how should I change the Source in order to point to the usercontrol itself?
found also an other variant (that I used, by the way) thanks!
3
<UserControl x:Name="MyStopControl" >
    ...
    <Pen Brush="{Binding ElementName=MyStopControl, Path=TextForeground}"/>
    ...
</UserControl>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.