使用WPF中的相同按钮显示和隐藏图片 [英] Show and hide picture using the same button in WPF
问题描述
下面的程序在单击按钮时隐藏了一张图片,
我想要的程序是检查是否隐藏了visibility属性,如果是,则将其设置为可见,以及是否可见,将其设置为隐藏。所以通过点击相同的按钮来连续显示和隐藏图片。
我想这可以通过某种IF命令实现,但是自从我昨天开始以来我真的很少掌握WPF
你能给我一些WPF中IF命令的例子,或者我如何在这个程序中进行...
谢谢
我尝试过:
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;
}
}
}
推荐答案
if ( linevertical.Visibility == Visibility.Hidden ){
linevertical.Visibility = Visibility.Visible;
} else{
linevertical.Visibility = Visibility.Hidden;
}
这篇关于使用WPF中的相同按钮显示和隐藏图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!