I have some button that I want them to be hidden when the wpf loads up. I use this:
public MainWindow()
{
mySendButton.Visibility = Visibility.Hidden;
myReceiveButton.Visibility = Visibility.Hidden;
InitializeComponent();
}
But the above generating an error. i think I wrote them not at the right place. Can I get a help please?
InitializeComponent
Method initializes the components, in your case buttons. Your buttons beforeInitializeComponent
call isnull
because they are not initialized and setting its visibility throws the exception.That's why in some languages it is written
You need to do
BTW, you can set the visibility in XAML like this.