gpt4 book ai didi

wpf - 如何启用/禁用 wpf 中的按钮

转载 作者:行者123 更新时间:2023-12-04 16:52:32 25 4
gpt4 key购买 nike

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

编辑

<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>

enter image description here
您可以通过 xaml 禁用捕获,然后通过在 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 事件。

关于wpf - 如何启用/禁用 wpf 中的按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28338223/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com