开发者

How to programmatically create rectangle and textblock with binding element with c#?

开发者 https://www.devze.com 2023-03-26 20:21 出处:网络
I have the following code, which i want to programmatically create. Where the i is must be an integer into xaml! This is a sample Code from VISIBLOX.

I have the following code, which i want to programmatically create. Where the i is must be an integer into xaml! This is a sample Code from 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" />

I can create a most programmatically but im stucking since 2 days with the Path=Behaviour.Behaviours[0].CurrentPoints[i].Y impossible for me to see how i can programmatically create it!

Thank u for help

Edit

IT's Work

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);


Presumably you're going to be building this Binding in a for loop of some sort?

If so, can't you do something like:

Binding b = new Binding { Path = new PropertyPath("Behaviour.Behaviours[0].CurrentPoints[" + i +"].Y”) };

Where the i there is the indexer in the for loop? I'm not sure I fully understand the problem so maybe you could elaborate with a bit more context?

If you’re trying to bind to a different thing depending on what is available in CurrentPoints, you might need to just bind to Benaviour.Behaviours[0] and use a converter to return the correct point’s Y value.

If you need any more help just let me know!

0

精彩评论

暂无评论...
验证码 换一张
取 消