CheckBox in Silverlight 5
Step 1) Checkbox has 3 states 1.checked 2.Unchecked 3.indeterminate(default not enabled).
It will be used for multiple selection options.
for ex: programmer has skills C#,VB.NET,JAVA and PHP.
Step 2) In this example added 3 check boxes
YES,NO,N/A check box.
Button controls navigates all these check boxes and displays selected checkboxes values.
<CheckBox Content="Yes"
HorizontalAlignment="Left"
VerticalAlignment="Top" />
<CheckBox Content="No"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Margin="0,40,0,0"/>
<CheckBox Content="N/A"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Margin="0,88,0,0"/>
<Button Content="Get Checked Buttons"
x:Name="checked_Button_List"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Width="254" Margin="10,265,0,0"
Click="checked_Button_List_Click"/>
<sdk:Label Background="Gray"
Name="txtChkStatus"
HorizontalAlignment="Left"
Height="97"
Foreground="WhiteSmoke"
VerticalAlignment="Top"
Width="254" Content=""
Margin="10,163,0,0"/>
<sdk:Label Content="Checkbox in Silverlight 5"
FontSize="25"
Foreground="Gray"
Margin="10,330,-10,91"
FontFamily="Comic Sans MS"
RenderTransformOrigin="0.513,4.359"
>
<sdk:Label.Background>
<LinearGradientBrush
StartPoint="0.30,0.2"
EndPoint="0.30,0.99">
<GradientStop
Color="Yellow"
Offset="0.5">
</GradientStop>
<GradientStop
Color="YellowGreen"
Offset="1.5">
</GradientStop>
</LinearGradientBrush>
</sdk:Label.Background>
</sdk:Label>
HorizontalAlignment="Left"
VerticalAlignment="Top" />
<CheckBox Content="No"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Margin="0,40,0,0"/>
<CheckBox Content="N/A"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Margin="0,88,0,0"/>
<Button Content="Get Checked Buttons"
x:Name="checked_Button_List"
HorizontalAlignment="Left"
VerticalAlignment="Top"
Width="254" Margin="10,265,0,0"
Click="checked_Button_List_Click"/>
<sdk:Label Background="Gray"
Name="txtChkStatus"
HorizontalAlignment="Left"
Height="97"
Foreground="WhiteSmoke"
VerticalAlignment="Top"
Width="254" Content=""
Margin="10,163,0,0"/>
<sdk:Label Content="Checkbox in Silverlight 5"
FontSize="25"
Foreground="Gray"
Margin="10,330,-10,91"
FontFamily="Comic Sans MS"
RenderTransformOrigin="0.513,4.359"
>
<sdk:Label.Background>
<LinearGradientBrush
StartPoint="0.30,0.2"
EndPoint="0.30,0.99">
<GradientStop
Color="Yellow"
Offset="0.5">
</GradientStop>
<GradientStop
Color="YellowGreen"
Offset="1.5">
</GradientStop>
</LinearGradientBrush>
</sdk:Label.Background>
</sdk:Label>
In the Button Handler, Loops through all controls in the Grid Layout and gets CheckBox List, in that selected one's displayed on the label.
C#
private void checked_Button_List_Click(
object sender, RoutedEventArgs e)
{
txtChkStatus.Content = String.Empty;
var chkQuery =
LayoutRoot.Children.OfType<CheckBox>();
foreach (CheckBox chk in chkQuery)
{
if (chk.IsChecked.HasValue
&& chk.IsChecked.Value==true)
txtChkStatus.Content +=
chk.Content + " " + "Checked\r\n";
}
}
object sender, RoutedEventArgs e)
{
txtChkStatus.Content = String.Empty;
var chkQuery =
LayoutRoot.Children.OfType<CheckBox>();
foreach (CheckBox chk in chkQuery)
{
if (chk.IsChecked.HasValue
&& chk.IsChecked.Value==true)
txtChkStatus.Content +=
chk.Content + " " + "Checked\r\n";
}
}
VB.NET
Private Property checked_Button_List_Click(() As void
End Property
Object Function e)() As sender,RoutedEventArgs
txtChkStatus.Content = String.Empty
var chkQuery =
LayoutRoot.Children.OfType<CheckBox>()
Dim chk As CheckBox
For Each chk In chkQuery
If if(chk.IsChecked.HasValue Then
And chk.IsChecked.Value=True)
txtChkStatus.Content +=
chk.Content + " " + "Checked\r\n"
End If
Next
End Function
End Property
Object Function e)() As sender,RoutedEventArgs
txtChkStatus.Content = String.Empty
var chkQuery =
LayoutRoot.Children.OfType<CheckBox>()
Dim chk As CheckBox
For Each chk In chkQuery
If if(chk.IsChecked.HasValue Then
And chk.IsChecked.Value=True)
txtChkStatus.Content +=
chk.Content + " " + "Checked\r\n"
End If
Next
End Function
Checkbox Text on Left change flowdirection "right to left"
Tags:
CheckBox in Silverlight 5, Check box in Silverlight 5, CheckBox in XAML,Left Text Checkbox in XAML,Silverlight,WPF, Choice/options Checkbox in WPF,Get Selected Checkboxs value.

