0

I am so new in WPF ,i am trying to draw a map using WPF so i fetch the points from database as you can see here :

   lstSensorLeft = objSensorRepository.FindBy(i => i.Path.LineId == 1 && i.Direction == "Left").OrderBy(i => i.Order).ToList();
            PointCollection obj = new PointCollection();

            foreach (Sensor point in lstSensorLeft)
            {
                Point aaa=new Point();
                aaa.X = point.XLocation;
                aaa.Y = point.YLocation;
            }
            Lines.Points = obj; 

In Xaml part i have this code :

 <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="500*"/>
            <ColumnDefinition Width="93*"/>
        </Grid.ColumnDefinitions>
        <Polyline  Stroke="Blue" StrokeThickness="2" Name="Lines" Grid.ColumnSpan="2"/>
        <Button Content="Button" HorizontalAlignment="Left" Margin="74,283,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click_2"/>
    </Grid>

But the lines don't appear.

loop
  • 9,002
  • 10
  • 40
  • 76
Ehsan Akbar
  • 6,977
  • 19
  • 96
  • 180

1 Answers1

1

Inside your foreach loop, you do not add the new point to the collection. E.g. something like this is missing:

obj.Add(aaa);
  • Thank you ,It works but one more question i need that every point be a circle should i change any thing in code? – Ehsan Akbar Jul 08 '14 at 08:20
  • 1
    If you want to represent every point as a circle, then I would suggest that you use a `ItemsControl` instead of the `Polyline`, and add every point as an item to the control. The panel of the items control should be a `Canvas`, and the X and Y coordinates of the points should be bound to the `Canvas.Left` and `Canvas.Top` properties. Something similar is described in this answer: http://stackoverflow.com/questions/19797737/datatemplates-to-display-a-collection-of-points-as-ellipses-in-wpf . –  Jul 08 '14 at 08:25
  • Thank you .You know i should draw a train line and show online train on this map with animation ,so could you please suggest me which method should i use? – Ehsan Akbar Jul 08 '14 at 08:29