Hello,
Welcome to Microsoft Q&A.
You can try to create the DependencyProperty of a page/usercontrol and bind it. When you press the button, you only need to modify this property to change the visibility of the control.
FlowerUserControl.xaml
...
<StackPanel Grid.Row="1" Orientation="Vertical" x:Name="stackPanelInfo" Visibility="{x:Bind DescriptionVisibility,Mode=OneWay}">
<TextBlock x:Name="txtLocation"/>
<TextBlock x:Name="txtDescription"/>
</StackPanel>
...
FlowerUserControl.xaml.cs
public Visibility DescriptionVisibility
{
get { return (Visibility)GetValue(DescriptionVisibilityProperty); }
set { SetValue(DescriptionVisibilityProperty, value); }
}
// Using a DependencyProperty as the backing store for DescriptionVisibility. This enables animation, styling, binding, etc...
public static readonly DependencyProperty DescriptionVisibilityProperty =
DependencyProperty.Register("DescriptionVisibility", typeof(Visibility), typeof(FlowerUserControl), new PropertyMetadata(Visibility.Collapsed));
MainPage.xaml
<Grid>
<FlowerUserControl x:Name="Flower1" DescriptionVisibility="{x:Bind FlowerVisibility, Mode=OneWay}"/>
<FlowerUserControl x:Name="Flower2" DescriptionVisibility="{x:Bind FlowerVisibility, Mode=OneWay}"/>
<FlowerUserControl x:Name="Flower3" DescriptionVisibility="{x:Bind FlowerVisibility, Mode=OneWay}"/>
</Grid>
MainPage.xaml.cs
public Visibility FlowerVisibility
{
get { return (Visibility)GetValue(FlowerVisibilityProperty); }
set { SetValue(FlowerVisibilityProperty, value); }
}
public static readonly DependencyProperty FlowerVisibilityProperty =
DependencyProperty.Register("FlowerVisibility", typeof(Visibility), typeof(MainPage), new PropertyMetadata(Visibility.Visible));
void btnCollapseAll_Click(object sender, RoutedEventArgs e)
{
FlowerVisibility = Visibility.Collapsed;
}
Thanks.