Question

J'ai un contrôle simple avec du code pour ajouter des chemins. Lorsque j'ajoute mon contrôle à la grille de contrôle, rien ne s'affiche. Pour être sûr de ne pas être fou, j'ai débogué dans le code, créé un équivalent XAML et l'ai placé à côté de l'endroit où mon contrôle devrait apparaître. J'ai essayé de changer l'index z et diverses combinaisons Top / Left pour essayer d'obtenir mon chemin, mais pas de chance. Mes contrôles appartiennent à la collection d'enfants Canvas, mais ils ne veulent tout simplement pas apparaître! Voici mon code

for (int i = 0; i < 4; i++)
{
    SolidColorBrush brush = new SolidColorBrush();
    brush.Color = GetColor();

    path = new Path();
    path.Data = getData(i);
    path.Name = i.ToString();
    path.SetValue(Canvas.LeftProperty, 150.0);
    path.SetValue(Canvas.TopProperty, 150.0);
    path.SetValue(Canvas.ZIndexProperty, 1000);
    path.Fill = brush;
    mainLayout.Children.Add(path);
}

Et voici le XAML. Les chemins codés en dur ici sont les chemins que j'ai créés en parcourant le code.

<Canvas Name="mainLayout">
    <Path Name="Path5" Fill="Red" Canvas.Left="450" Canvas.Top="150" Data="M 0,-100 A 100,100 0.628332123128715 0 1 58.7796248729471,-80.9009004881628 L 0,0" ></Path>
    <Path Name="Path6" Fill="Green" Canvas.Left="450" Canvas.Top="150" Data="M 58.7796248729471,-80.9009004881628 A 100,100 0.559576083957105 0 1 92.7589501245075,-37.3601013355041 L 0,0" ></Path>
    <Path Name="Path7" Fill="Blue" Canvas.Left="450" Canvas.Top="150" Data="M 92.7589501245075,-37.3601013355041 A 100,100 3.11153310318617 0 1 -91.5941871397306,40.1310961999795 L 0,0" ></Path>
    <Path Name="Path8" Fill="Yellow" Canvas.Left="450" Canvas.Top="150" Data="M -91.5941871397306,40.1310961999795 A 100,100 1.98374399690759 0 1 -1.1330996904646E-13,-100 L 0,0" ></Path>
</Canvas>

Lorsque je lance tout, seuls les chemins codés en dur apparaissent.

Était-ce utile?

La solution

Deux questions rapides, lorsque vous y êtes intervenu, getDate (i) a renvoyé un chemin, et getColor () a renvoyé autre chose que couleurs.transparent

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top