상세 컨텐츠

본문 제목

[Silverlight] Create CheckBoxList in Silverlight

Web Development/Silverlight

by thankee 2009. 11. 16. 20:25

본문

ASP.NET에서 제공하는 CheckBoxList나 RadioButtonList 등은 Silverlight에서는 직접 구현하셔야 합니다. Silverlight에서는 특정 컨트롤을 반복 시켜주는 컨트롤로 ItemsControl을 제공하기 때문에 CheckBoxList를 쉽게 구현하실 수 있습니다. Silverlight의 ComboBox, ListBox Control도 모두 이 ItemsControl을 상속하여 구현되었습니다.

여기서는 ItemsControl을 이용하여 ASP.NET의 CheckBoxList를 구현하는 소스코드를 간단히 소개하도록 하겠습니다.

소스코드

<ItemsControl ItemsSource="{Binding ServiceList}">
    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <!-- 여기서 각 컨트롤들을 포함하는 FrameworkElement를 설정합니다. -->
            <StackPanel Orientation="Horizontal" />
        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <!--여기서는 FrameworkElement에 포함될 Control들을 설정합니다. -->
            <CheckBox Content="{Binding Name}" IsChecked="{Binding Value}" />
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>

결과

관련글 더보기