2010-11-18 25 views
0

Je dois lier la propriété de dépendance personnalisée aux éléments Image d'un contrôle.Aide sur la liaison WPF

Maintenant Foreground du Label se fixe très bien à TextForeground, mais pas à l'intérieur du GeometryDrawingImage (l'image reste transparent).

Qu'est-ce qui ne va pas?

<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> 

Répondre

3

GeometryDrawing n'a pas une propriété TextForeground. Vous référencez le Soi, qui serait le GeometryDrawing. Changez votre RelativeSource si vous essayez d'attraper le TextForeground à partir d'un autre contrôle.

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

** MyStopControl ** a la propriété 'TextForeground'. Donc, par exemple pour le Label> 'Foreground =" {Binding ElementName = TextForeground} "' fonctionne très bien. – serhio

+0

@serhio Vous référencez RelativeSource = {x: Static RelativeSource.Self} sur GeometryDrawing cependant ... dans l'étiquette vous n'êtes pas –

+0

alors comment changer la Source pour pointer vers la commande usercontrol? – serhio

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