如何启用/禁用 wpf 中的按钮 [英] How to Enable/Disable button in wpf

查看:183
本文介绍了如何启用/禁用 wpf 中的按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 2 个按钮,开始和捕获.我想在表单加载时禁用捕获按钮并启用启动.然后单击开始禁用开始按钮并启用捕获.请帮我.提前致谢

I Have 2 button , Start And capture. I want disable capture button on form load and enable start. and on after click on start disable start button and enable capture. Please help me. Thanks in advance

编辑

<Grid>
    <Button Content="Button" Height="77" HorizontalAlignment="Left" Margin="92,151,0,0" Name="button1" VerticalAlignment="Top" Width="109">
        <Button.Background>
            <ImageBrush ImageSource="/WpfApplication1;component/Images/images.jpg" />
        </Button.Background>
    </Button>
    <Button Content="Button" Height="77" HorizontalAlignment="Left" Margin="229,151,0,0" Name="button2" VerticalAlignment="Top" Width="112" IsEnabled="False" >
        <Button.Background>
            <ImageBrush ImageSource="/WpfApplication1;component/Images/images.jpg" />
        </Button.Background>
    </Button>
</Grid>

推荐答案

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <Button Name="BStart" Content="Start" Width="100" Height="50" HorizontalAlignment="Left" Click="BStart_Click" />
        <Button Name="BCapture" Content="Capture" Width="100" Height="50" HorizontalAlignment="Right" IsEnabled="False" />
    </Grid>
</Window>


您可以通过 xaml 禁用捕获,然后通过在 c# 中编写代码启用它.


you can disable Capture by xaml and then enable it by writing code in c#.

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 WpfApplication1
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void BStart_Click(object sender, RoutedEventArgs e)
        {
            BStart.IsEnabled = false;
            BCapture.IsEnabled = true;
        }
    }
}

启用和禁用使用 IsEnabled 属性.并点击按钮使用 Click 事件.

for enable and disable use IsEnabled Property. and for clicking on the button use Click event.

这篇关于如何启用/禁用 wpf 中的按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆