我对这种编码有点陌生,但我试图在计时器TextBlock
的每个滴答声中访问动态创建的属性(如 TextBlock.Tag、Name 等) 。StackPanel
我打算对每个属性做的TextBlock
是查看它的tag
属性是什么,以及它是否与条件匹配,以便计时器以TextBlock
某种方式更改属性。
因此,需要找到一种方法来对每个计时器 Tick 进行编码:“对于TextBlock.Tag
StackPanel 中的每个,如果TextBlock.Tag == this
,对 . 执行此操作TextBlock
。”
这是一些代码来帮助可视化我在做什么:
Xml代码:
<StackPanel Name="StackP" Margin="6,0,6,0"/>
C#代码:
{
for (var i = 0; i < MaxCountOfResults; ++i)
{
TextBlock SingleResult= new TextBlock { Text = Resultname.ToString(), FontSize = 20, Margin = new Thickness(30, -39, 0, 0) };
//a condition to alter certain TextBlock properties.
if (i == .... (irrelevant to this example))
{
SingleResult.Foreground = new SolidColorBrush(Colors.Yellow);
SingleResult.Tag = "00001";
}
//Add this dynamic TextBlock to the StackPanel StackP
StackP.Children.Add(SingleResult);
}
//the timer that starts when this entire function of adding the TextBlocks to the StackPanel StackP tree is done.
Atimer = new Timer(new TimerCallback(Atimer_tick), 0, 0, 100);
}
public void Atimer_tick(object state)
{
The area where I have no idea how to reference the Children of stackpanel StackP with every timer tick. I need help :(
}
谢谢你们。我仍在学习这一点,需要帮助。