我是WPF中的新手,我正在尝试使用WPF
绘制地图,所以我从数据库中获取点,如下所示:
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;
在Xaml部分我有这段代码:
<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>
但线条不会出现。
答案 0 :(得分:1)
在foreach
循环中,您不会将新点添加到集合中。例如。缺少这样的东西:
obj.Add(aaa);