In my application, there are ten textboxes child to Stack panel. I assigning text to textboxes in the Main Window function of c# script. I want to calculate the total height of the textboxes.
The problem is it is giving 0. Please look into the code below:
List<TextInfoData> newList = new List<TextInfoData>();
public MainWindow()
{
InitializeComponent();
for (int num = 0; num < 10; num++)
{
newList.Add(new TextInfoData("Sunset is the time of day when our sky meets the " +
"outer space solar winds. There are blue, pink, and purple swirls, spinning " +
"and twisting, like clouds of balloons caught in a blender.", 1));
}
RearrangeTextData(newList);
}
private void RearrageTextData(List<TextInfoData> textInfoData)
{
TextBox tbox = new TextBox();
//rest of code to define textbox margin and setting textwrapping to wrap
double totalTextBoxHeight = 0;
foreach (TextInfoData tinfoData in textInfoData)
{
tbox.Text = tinfoData.GetTextDataString();
totalTextBoxHeight += tbox.ActualHeight;
rootStackPanel.Children.Add(tbox);
}
MessageBox.Show("Total Height: " + totalTextBoxHeight);
}
I have a class TextInfoData which accepts string and integer two values as parameter. There is function GetTextDataString, which returns the string value.
The name of parent stack panel is rootStackPanel.
If I check total number of children of rootStackPanel, it is showing ten (which is right) but when I try to get total text box height, it gives 0. Please guide me.