Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide textboxes, labels and buttons C# WPF

I would like to hide several textboxes, a label and a button as soon as a button is clicked... however, for some reason, my code doesn't seem to cause this effect. Nothing appears to happen. I'm using WPF.

Here is my code:

private void doSomething_Click(object sender, RoutedEventArgs e)
    {

        Name.Visibility = Visibility.Hidden; 

    }

This code doesn't seem to work.. any ideas?

like image 820
BigBug Avatar asked Nov 27 '11 07:11

BigBug


2 Answers

I believe Visibility.Collapsed is what you need and not Visibility.Hidden.

EDIT: Did you try follow up this code with UpdateLayout() method of parent element/component?

like image 75
nikola-miljkovic Avatar answered Oct 19 '22 13:10

nikola-miljkovic


Your code seems to work fine, the "Signing in..." label appears after everything else disappear. I suggest you to just copy all your code from the .xaml.cs file and the .xaml file into a new project, but make sure you don't copy the first line"<Window x:Class="..." because it could generate an error if the class name isn't the same in the new project.

For the xaml code I suggest you not think the same as you design windows forms applications. WPF has the layout system, which re-orientates or re-sizes its elements when re-sizing the window. So you should not specify exact numbers in the margin property as if they where coordinates. Create a grid, create rows or columns for each element and then just set the horizontal or vertical alignment or margins. Think different than the old windows forms way.

like image 43
Cobold Avatar answered Oct 19 '22 15:10

Cobold