我有以下代码,我想以编程方式创建。其中i必须是 xaml 中的整数!这是来自 VISIBLOX 的示例代码。
<Rectangle Margin="20,0,0,5" Height="10" Width="10" Fill="{Binding ElementName=chart, Path=Series[i].LineStroke}" VerticalAlignment="Center" />
<TextBlock Margin="4,0,0,0" Text="{Binding ElementName=chart, Path=Series[i].DataSeries.Title}" />
<TextBlock Margin="4,0,0,0" Text="(" HorizontalAlignment="Left" />
<TextBlock Text="{Binding ElementName=chart, Path=Behaviour.Behaviours[0].CurrentPoints[i].Y, StringFormat=0.00}" Width="38" />
<TextBlock Text=")" HorizontalAlignment="Right" />
我可以以编程方式创建一个,但自 2 天以来我一直坚持使用Path=Behaviour.Behaviours[0].CurrentPoints[i].Y,我无法看到如何以编程方式创建它!
谢谢你的帮助
编辑
这是工作
TextBlock txtBlock3 = new TextBlock();
Binding txtBinding3 = new Binding();
txtBinding3.ElementName = "MainChart";
txtBinding3.Path = new PropertyPath("Behaviour.Behaviours[0].CurrentPoints[" + index +"].Y");
txtBlock3.SetBinding(TextBlock.TextProperty, txtBinding3);
txtBlock3.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
Panel.Children.Add(txtBlock3);