Thank you very much for your answer
I have made a mistake. I wanted to simplify the code, so I put the code in the button click. In fact, the code should be as soon as the buttons are generated. That's when he makes the mistake. The first message is zero with the height of the button. I need to get the height of the btnHeigt [index] buttons. If I don't put a MessageBox in there, all btnHeigt [index] are zero.
private void btnOpen_Click(object sender, RoutedEventArgs e)
{
for (int i = 1; i < indexMax + 1; i++)
{
var btn = new Button()
{
Content = i.ToString() + " " + textEnSRT[i] + " ",
HorizontalAlignment = HorizontalAlignment.Right,
Foreground = new SolidColorBrush(Colors.Black) { Opacity = 0.9 },
Background = new SolidColorBrush(Colors.LightGray) { Opacity = 0.4 },
BorderThickness = new Thickness(0, 0, 0, 0),
Margin = new Thickness(0, 2, 4, 0),
Tag = i,
FontSize = 16,
};
btn.Click += Btn_Click;
stackPanel1.Children.Add(btn);
}
// Now first bt.ActualHeight is zero;
foreach (Button bt in FindVisualChildren<Button>(stackPanel1))
{
MessageBox.Show(bt.Tag.ToString() + " " + bt.ActualHeight.ToString() + " " + bt.Content);
}
// I need next. But now is all btnHeigt [indexK] are zero.
]
foreach (Button bt in FindVisualChildren<Button>(stackPanel1))
{
btnHeight[indexK] = bt.ActualHeight.ToString();
indexK++;
}
}
Would you like help me
Best Regards