How to hide text fields, labels and buttons of C # WPF

I want to hide several text fields, a shortcut and a button as soon as the button is pressed ... however, for some reason, my code does not seem to cause such an effect. Nothing seems to be happening. I am using WPF.

Here is my code:

private void doSomething_Click(object sender, RoutedEventArgs e) { Name.Visibility = Visibility.Hidden; } 

This code does not seem to work .. any ideas?

+8
visibility c # wpf
source share
5 answers

Your code seems to be working fine, the inscription "Signing in ..." appears after everything else has disappeared. I suggest you simply copy all of your code from the .xaml.cs and .xaml file into a new project, but do not copy the first line "<Window x:Class="..." because it may generate an error if the class name does not match the new project.

For xaml code, I suggest you not think the same way you develop applications for Windows forms. WPF has a layout system that reorients or resizes elements when recalibrating a window. Thus, you should not specify exact numbers in the margin property, as if they were where the coordinates were. Create a grid, create rows or columns for each element, and then simply set the horizontal or vertical alignment or margins. Think differently than old window shapes.

+7
source share

I believe that Visibility.Collapsed is what you need, not Visibility.Hidden .

EDIT: Have you tried to execute this code using the UpdateLayout() method of the parent element / component?

+7
source share

I ran your code ... and it works great for me. I have not changed anything (except for variable names), so I assume this is an error from VS.

As nikolamm94 said, try adding this.UpdateLayout(); at the end of connect_Click , this may help. I tried and it still works fine. Or maybe create a new VS project, it has already worked for me several times.

Sorry, my answer is not the most useful, I wanted to put a comment instead, but I do not have enough reputation: /

+4
source share

You can hide the text field by going to properties-> view-> visibility, then setting it to "hidden"

0
source share

Please contact: https://msdn.microsoft.com/en-us/library/ms748821(v=vs.85).aspx

Set the Visible value: tb1.Visibility = System.Windows.Visibility.Visible;

Set to Hide: tb1.Visibility = System.Windows.Visibility.Hidden;

0
source share

All Articles