Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
The program below hides a picture when clicking a button,
What I want is the program to check if the visibility property is hidden, and if so, to set it visible, and if is visible, to set it hidden. So by clicking the same button to show and hide the picture successively.
I suppose this will be posible with some kind of IF command, but i really grasp very little of WPF since I began yesterday

Can you guys give me some example of IF command in WPF, or how can i procide in this program...

Thanks

What I have tried:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfApp2
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            linevertical.Visibility = Visibility.Hidden;
        }
    }
}
Posted
Updated 15-Mar-19 5:01am
v2

1 solution

C#
if ( linevertical.Visibility == Visibility.Hidden ){
   linevertical.Visibility = Visibility.Visible;
} else{
   linevertical.Visibility = Visibility.Hidden;
}
 
Share this answer
 
Comments
tool__ 15-Mar-19 11:20am    
I don't fully understand the statements but it works perfectly, can you educate me, what is the significance of == and why you start with visibility hidden? could you have started the statement with visibility visible?

Thanks again
Dylvh 16-Mar-19 15:42pm    
The == is to say "equal to". That is to check whether the value on the left is the same as the value on the right. For your second question the answer is yes, you can start the statement with visibility visible, but remember then to make sure you set the correct value for Visibility that makes logically sense for what you want to do.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900