2,854 questions
Try something like this:
private void Button1_Click(object sender, RoutedEventArgs e)
{
Border b = _stack0.Children[0] as Border;
if( b != null)
{
b.Background = . . .
}
}
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Unfortunately I can't find a way to access the children of a StackPanel directly (without creating a parallel list).
E.g. here as a demo to change the background color of a border via index.
Border border;
private void Button0_Click(object sender, RoutedEventArgs e)
{
border = new Border();
border.Background = new SolidColorBrush(Colors.Red);
_stack0.Children.Add(border);
border.Width = 100;
border.Height = 100;
border = new Border();
border.Background = new SolidColorBrush(Colors.Yellow);
_stack0.Children.Add(border);
border.Width = 75;
border.Height = 75;
border = new Border();
border.Background = new SolidColorBrush(Colors.Green);
_stack0.Children.Add(border);
border.Width = 50;
border.Height = 50;
}
private void Button1_Click(object sender, RoutedEventArgs e)
{
_stack0.Children[0].Opacity = 0.5;
//Change Background of Children[0] ???
}
Try something like this:
private void Button1_Click(object sender, RoutedEventArgs e)
{
Border b = _stack0.Children[0] as Border;
if( b != null)
{
b.Background = . . .
}
}