CheckBox 컨트롤
.NET프로그래밍/Silverlight 3.0 2009. 12. 2. 11:35 |[MainPage.xaml]
<UserControl x:Class="RiaCheckBox.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400">
<Grid x:Name="LayoutRoot" Background="White">
<StackPanel>
<StackPanel x:Name="my">
<TextBlock Text="당신의 관심사항은?"></TextBlock>
<CheckBox Content="C#" IsThreeState="False"></CheckBox>
<CheckBox Content="ASP.NET" IsChecked=""></CheckBox>
<CheckBox Content="Silverlight" IsChecked="True"></CheckBox>
</StackPanel>
<TextBlock><LineBreak></LineBreak></TextBlock>
<CheckBox x:Name="chkShow" IsThreeState="False" Content="보이기" />
</StackPanel>
</Grid>
</UserControl>
[MainPage.xaml.cs]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
namespace RiaCheckBox
{
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
this.chkShow.Click += new RoutedEventHandler(chkShow_Click);
}
void chkShow_Click(object sender, RoutedEventArgs e)
{
// 클릭한 개체가 체크박스인지 확인
CheckBox c = new CheckBox();
if (sender is CheckBox) // is 연산자 : ~개체이냐? true/false
{
c = sender as CheckBox; // 체크박스이면 해당 개체를 담고, 그렇지 않으면 null값을 담는다.
}
if (c == null) return;
bool chk = c.IsChecked ?? false; // null이 아니면(true이면) true, 그렇지 않으면 기본값인 false를 지정해주는 '??연산자'
// my 개체에 대해서 보임/숨김
my.Visibility = chk ? Visibility.Visible : Visibility.Collapsed; // 3항연산자
}
}
}
'.NET프로그래밍 > Silverlight 3.0' 카테고리의 다른 글
ScrollViewer 컨트롤 (0) | 2009.12.02 |
---|---|
ToolTip 컨트롤 (풍선도움말 제공) (0) | 2009.12.02 |
RadioButton 컨트롤 (0) | 2009.12.02 |
RepeatButton 컨트롤 (0) | 2009.12.02 |
HyperlinkButton 컨트롤 (0) | 2009.12.02 |