我必须在网格中绘制一些路径,这些路径定义存储在数据库中,如下所示:
<Path x:Name="MyPath" Data="M0.073363333,7.3695667 L6.8231533,0.032799774 13.131994,0.1797551 0.073726657,14.118345 0.22044918,7.6625736 0.073726657,24.388874 8.1436304,24.45903 32.86621,0.1063924 26.116795,-0.040326216 1.1813478,24.399203 24.25612,24.559788 49.152072,0.10626289 41.963089,0.03290334 17.610519,24.513989 0.062195513,24.390331 0.078522714,24.388897 43.226538,24.706345 65.933927,2.4904153 65.952566,0.014562738 61.092016,0.087921331 36.910362,24.648632 0.075087122,24.388897 59.64313,24.791428 65.842163,18.262777
65.842163,11.440329 53.139979,24.754434 0.078522714,24.392332" Fill="#FF2764BB" HorizontalAlignment="Left" Height="24.833" Margin="0.073,-0.04,0,0" Stretch="Fill" VerticalAlignment="Top" Width="65.892"/>
可以将此路径直接插入到我的网格中,还是需要构建自定义对象,然后将每个属性分配给我的自定义对象?
答案 0 :(得分:1)
您可以在代码隐藏中创建Path对象,如下所示:
Path path = new Path()
{
Data = dal.DataPath;
Fill = dal.FillColumn;
HorizontalAlignment = (System.Windows.HorizontalAlignment)dal.Hori;
//etc.
//you get the gist
};
请记住,此路径继承自ShapeE,这是一个FrameworkElement,因此您可以使用其中的许多网格填充网格。
<Grid x:Name="theGrid" ></Grid>
theGrid.Children.Add(path);
您还可以按如下方式设置路径的行或列:
Grid.SetRow(path,0);