RadioButton - Windows Phone Controls |
RadioButton - Windows Phone Controls สำหรับ RadioButton บน Windows Phone เป็น Controls สำหรับสร้าง Item ของรายการข้อมูลที่สามารถเลือกได้เพียงรายการใดรายการหนึ่ง
XAML
<RadioButton .../>
-or-
<RadioButton ...>
content
</RadioButton>
-or-
<RadioButton ...>stringContent</RadioButton>
Example ตัวอย่างการใช้ RadioButton บน Windows Phone
XAML
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!--TitlePanel contains the name of the application and page title-->
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<TextBlock x:Name="ApplicationTitle" Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock x:Name="PageTitle" Text="page name" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel>
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<Button Content="Submit" Height="72" HorizontalAlignment="Left" Margin="148,213,0,0" Name="btnSubmit" VerticalAlignment="Top" Width="160" />
<TextBlock Height="30" HorizontalAlignment="Center" Margin="48,321,58,0" Name="txtResult1" Text="Result 1" VerticalAlignment="Top" Width="350" TextAlignment="Center" />
<TextBlock Height="30" HorizontalAlignment="Center" Margin="48,357,58,0" Name="txtResult2" Text="Result 2" VerticalAlignment="Top" Width="350" TextAlignment="Center" />
<RadioButton Content="Item 1" Height="72" HorizontalAlignment="Left" Margin="148,71,0,0" Name="Raido1" VerticalAlignment="Top" />
<RadioButton Content="Item 2" Height="72" HorizontalAlignment="Left" Margin="148,135,0,0" Name="Raido2" VerticalAlignment="Top" />
</Grid>
</Grid>
VB.NET
Private Sub btnSubmit_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles btnSubmit.Click
Me.txtResult1.Text = If(Me.Raido1.IsChecked, "RadioButton Item 1 is Checked", "RadioButton Item 1 is UnChecked")
If Me.Raido2.IsChecked = True Then
Me.txtResult2.Text = "RadioButton Item 2 is Checked"
Else
Me.txtResult2.Text = "RadioButton Item 2 is UnChecked"
End If
End Sub
C#
private void btnSubmit_Click(System.Object sender, System.Windows.RoutedEventArgs e)
{
this.txtResult1.Text = this.Raido1.IsChecked ? "RadioButton Item 1 is Checked" : "RadioButton Item 1 is UnChecked";
if (this.Raido2.IsChecked == true) {
this.txtResult2.Text = "RadioButton Item 2 is Checked";
} else {
this.txtResult2.Text = "RadioButton Item 2 is UnChecked";
}
}
Screenshot
แสดง RadioButton บนหน้าจอ App และการอ่านค่าจาก RadioButton
|