I have canvas with few labels, lines and rectangles. I want to get only Labels from canvas, and then to replace with another labels. Is it possible to get only labels? I try to foreach elements but is give me exception:
Unable to cast object of type 'System.Windows.Shapes.Line' to type 'System.Windows.Controls.Label'.
I try with this code:
foreach (System.Windows.Controls.Label child in canvas.Children)
{
try
{
double.Parse(child.Content.ToString());
}
catch (FormatException)
{
continue;
}
canvas.Children.Remove(child);
}
Anybody know how can get only labels from canvas.
Thanks in advance