Search This Blog

Wednesday, October 30, 2013

WPF Checkbox

WPF > Controls  > ContentControl > CheckBox

WPF Checkbox  is a control that a user can check/uncheck and clear


WPF Checkbox Example:

XAML:

<Grid>
   <TextBox x:Name="txt1" HorizontalAlignment="Left" TextWrapping="Wrap" Text="TextBox"     Width="215" Margin="0,27,0,220"/>
<CheckBox x:Name="chkBox" Content="CheckBox" HorizontalAlignment="Left" VerticalAlignment="Top" Checked="chkBox_Checked" Unchecked="chkBox_Unchecked" Indeterminate="chkBox_Indeterminate" IsThreeState="True"/>
</Grid>

C# Code:

private void chkBox_Checked(object sender, RoutedEventArgs e)
{
   txt1.Text = "chkBox checked";
}
private void chkBox_Unchecked(object sender, RoutedEventArgs e)
{
   txt1.Text = "chkBox unchecked";
}
private void chkBox_Indeterminate(object sender, RoutedEventArgs e)
{
   txt1.Text = "chkBox indeterminate";
}