2012-11-26 4 views
1

Je souhaite tracer des lignes entre ScatterViewItems mais cela ne fonctionne pas avec ce que j'ai déjà trouvé ici. Il y a une ligne, mais pas connectée au centre des ellipses. Est-ce que quelqu'un voit mon erreur? Voici ce que j'ai:Connexion de ScatterViewItems avec une ligne

<Grid> 
    <s:ScatterView> 
     <s:ScatterViewItem Height="250" Width="500" Background="Transparent" Orientation="0" HorizontalAlignment="Right" Margin="0,70,-764,-70" d:LayoutOverrides="HorizontalAlignment, Width"> 
      <s:ScatterView Height="250" Width="500" Background="BlueViolet"> 
       <s:ScatterViewItem Background="Transparent" Center="100,145" Orientation="0"> 
        <Label Content="Knoten A" Background="WhiteSmoke" Foreground="Black"/> 
       </s:ScatterViewItem> 
       <s:ScatterViewItem x:Name="StartItem" CanMove="False" CanRotate="False" Margin="0" Center="10,125" Background="Transparent"> 
        <Ellipse Width="10" Height="10" Fill="Transparent" Stroke="Black" Margin="0,0,0,0"/> 
       </s:ScatterViewItem> 
       <s:ScatterViewItem x:Name="EndItem" CanMove="False" CanRotate="False" Margin="0" Center="490,125" Background="Transparent"> 
        <Ellipse Width="10" Height="10" Fill="Transparent" Stroke="Black" Margin="0,0,0,0"/> 
       </s:ScatterViewItem> 
       <s:ScatterViewItem Background="Transparent"> 
        <Canvas Name="LineHost"/> 
       </s:ScatterViewItem> 
      </s:ScatterView> 
     </s:ScatterViewItem> 
    </s:ScatterView> 
</Grid> 

Et C#

Line line = new Line { Stroke = Brushes.Black, StrokeThickness = 2.0 }; 
     BindLineToScatterViewItems(line, StartItem, EndItem); 
     LineHost.Children.Add(line); 

private void BindLineToScatterViewItems(Line line, ScatterViewItem StartItem, ScatterViewItem EndItem) 
    { 
     BindingOperations.SetBinding(line, Line.X1Property, 
            new Binding {Source = StartItem, Path = new PropertyPath("ActualCenter.X")}); 
     BindingOperations.SetBinding(line, Line.Y1Property, 
            new Binding { Source = StartItem, Path = new PropertyPath("ActualCenter.Y") }); 

     BindingOperations.SetBinding(line, Line.X2Property, 
            new Binding { Source = EndItem, Path = new PropertyPath("ActualCenter.X") }); 
     BindingOperations.SetBinding(line, Line.Y2Property, 
            new Binding { Source = EndItem, Path = new PropertyPath("ActualCenter.Y") }); 
    } 

line somewhere in the middle

Répondre

0

Le startpoint et le point final de vos lignes est ActualCenter.X/ActualCenter.Y de votre StartItem. Si l'ActualCenter de votre Startitem est 10/100, vous traceriez une ligne de 10/100 à 10/100, ce qui est une raison pour laquelle vous ne voyez aucune ligne. Au lieu de définir Source = Startitem dans les deux dernières lignes de votre méthode BindLineToScatterViewItems, essayez de définir Source = EndItem.

Espérons que cela aide.

+0

Merci, je viens de le voir, aussi ;-) Maintenant, la ligne est là, mais pas connecté aux ellipses. Une idée pourquoi? – Judith

+0

Pourriez-vous poster une capture d'écran de s'il vous plaît? ;) –

+0

Nous sommes désolés, mais en tant que mécanisme de prévention du spam, les nouveaux utilisateurs ne sont pas autorisés à publier des images. Gagnez plus de 10 points de réputation pour poster des images. ^^ – Judith

0

Si je toile au lieu de ScatterView et ScatterViewItem et le ist ordre comme celui-ci

<s:ScatterView> 
     <Canvas Name="LineCanvas2" Width="500" Height="250" Background="Aquamarine"> 
      <Canvas Background="Transparent" Name="LineCanvas"/> 
      <s:ScatterView Width="500" Height="250" Background="Transparent"> 
       <s:ScatterViewItem ... 

il n'y a pas de problème avec le positionnement des lignes de connexion.

Questions connexes