S
S
Segio2018-06-28 19:26:23
WPF
Segio, 2018-06-28 19:26:23

How to hide buttons on click in WPF?

There are 4 buttons with visible:hide and 4 buttons that are in the same place are visible. When you click OK, the invisible ones should become visible. I don't know how to implement.
Isn't there something like css, where the tags are given the same classes, then this class is given common properties?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Nemiro, 2018-06-28
@CiSharper

Place buttons in a container and change the visibility status of the container:

<Button Content="Ok" HorizontalAlignment="Left" VerticalAlignment="Top" 
  Width="75" Margin="0,75,0,0" 
  Click="Button_Click"
/>

<WrapPanel Name="Buttons" Orientation="Horizontal">
  <Button Name="Button1" Content="Button" HorizontalAlignment="Left" 
    VerticalAlignment="Top" Width="75"
  />
  <Button Name="Button2" Content="Button" HorizontalAlignment="Left" 
    VerticalAlignment="Top" Width="75" 
  />
  <Button Name="Button3" Content="Button" HorizontalAlignment="Left" 
    VerticalAlignment="Top" Width="75" 
  />
  <Button Name="Button4" Content="Button" HorizontalAlignment="Left" 
    VerticalAlignment="Top" Width="75"
  />
</WrapPanel>

private void Button_Click(object sender, RoutedEventArgs e)
{
  Buttons.Visibility = Visibility.Hidden; // Visibility.Visible

  /*
  if (Buttons.Visibility == Visibility.Hidden)
  {
    Buttons.Visibility = Visibility.Visible;
  }
  else
  {
    Buttons.Visibility = Visibility.Hidden;
  }
  */
}

D
d-stream, 2018-06-29
@d-stream

WPF naturally implies mvvm. Well, in mvvm-style, the visibility property of buttons or their container should be bound to a property that changes, for example, when a command is executed.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question