如何在WPF中基于复选框启用/禁用文本框和标签?

时间:2018-09-28 07:47:03

标签: c# wpf xaml user-interface

如何根据 WPF ??

中的Label输入来启用或禁用textboxcheckbox

复选框

<CheckBox Style="{StaticResource CheckBoxStyle1}"  Foreground="#FFF9F3F3" HorizontalAlignment="Left" Margin="32.844,-5.293,0,0" Width="216" Content="Sim Needs Passwprd?" Grid.Column="1" Grid.Row="2" Height="18.043" VerticalAlignment="Top" FontSize="14" Background="#FFF4F4F4"/>

文本框和标签

<Label  Style="{StaticResource LabelTitle}" Content="Sim User Name" Margin="14.439,17.192,-83.497,15"  d:IsStaticText="True" Background="#00D32626" x:Name="Label_SimUName" d:LayoutOverrides="Width, Height" Grid.Row="2" />
<Border Style="{StaticResource BorderTextBox}" Grid.Column="1" Grid.Row="2" Margin="29.844,15.885,0,16.307" d:LayoutOverrides="Height" HorizontalAlignment="Left" Width="288">
    <TextBox Style="{StaticResource ValueTextBox_Sim}" HorizontalAlignment="Stretch" Margin="0,0,0,0"  Grid.Column="1" Text="TextBox" x:Name="TextBox_SimUName" ClipToBounds="False" VerticalAlignment="Stretch" Width="286"/>
</Border>

<Label  Style="{StaticResource LabelTitle}" Content="Sim Password" Margin="14.439,-4,-83.497,0"  d:IsStaticText="True" Background="#00D32626" x:Name="Label_SimPassword" d:LayoutOverrides="Width, Height" Grid.Row="3" VerticalAlignment="Top" />
<Border Style="{StaticResource BorderTextBox}" Grid.Column="1" Grid.Row="3" Margin="29.844,-5.307,0,0" d:LayoutOverrides="Height" HorizontalAlignment="Left" Width="288" VerticalAlignment="Top">
    <TextBox Style="{StaticResource ValueTextBox_Sim}" HorizontalAlignment="Stretch" Margin="0,0,0,0"  Grid.Column="1" Text="TextBox" x:Name="TextBox_SimPassword" ClipToBounds="False" VerticalAlignment="Stretch" Width="288"/>
</Border>

有人可以帮我吗?

2 个答案:

答案 0 :(得分:1)

  1. 在复选框上创建事件
  2. 使用此C#命令:

    yourObject.IsEnabled = true / false;


更多帮助:Disable button in WPF?

答案 1 :(得分:1)

将选中和未选中的事件添加到您的复选框中,如下所示:XAML

Select Order.Alias, Customer.Alias
from Db.SchmaName.Orders as Order
INNER JOIN Db.SchmaName.Customers as Customer on Order.Alias = Customer.Alias

并在其.cs文件中执行此操作。

<CheckBox Style="{StaticResource CheckBoxStyle1}"   Foreground="#FFF9F3F3" HorizontalAlignment="Left" Margin="32.844,-5.293,0,0" 
Width="216" Content="Sim Needs Passwprd?" Grid.Column="1" Grid.Row="2" Height="18.043" VerticalAlignment="Top" FontSize="14" Background="#FFF4F4F4" Checked="CheckBox_Checked" Unchecked="CheckBox_Unchecked"/>

您可以基于未选中或选中的事件启用文本框和标签。