TOC

This article is currently in the process of being translated into Korean (~90% done).

The ListView control:

A simple ListView example

WPF ListView 컨트롤은 가장 간단한 형태에서는 매우 기본적입니다. 실제로 당신이 특별한 뷰들을 ListView에 추가하기 전까진 WPF ListBow와 완전히 비슷해 보일 것입니다. ListView는 ListBox 컨트롤로 부터 직접상속 받기 때문에 그것은 이상한게 아닙니다. 그래서 기본 ListView는 실제로 여러 선택 모드가 있는 ListBox입니다. (나중에 더 자세히 설명합니다.)

가장 간단한 형태로 ListView를 만들어 봅시다.

<Window x:Class="WpfTutorialSamples.ListView_control.ListViewBasicSample"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="ListViewBasicSample" Height="200" Width="200">
    <Grid>
		<ListView Margin="10">
			<ListViewItem>A ListView</ListViewItem>
			<ListViewItem IsSelected="True">with several</ListViewItem>
			<ListViewItem>items</ListViewItem>
		</ListView>
	</Grid>
</Window>

이것은 list를 채우기 위해 수동으로 만든 ListViewItem을 사용하고 아무것도 가지지 않은 가장 간단한 형태의 ListView지만 text label이 각 아이템을 표시하고 있습니다. - 간단한 WPF ListView control

이미지를 포함한 ListViewItem

WPF의 look-less 특성 때문에 ListViewItem에 이미지를 설정하는 것은 단지 속성에 image ID 혹은 key를 할당하는 것이 아닙니다. 대신에 당신은 이를 완전히 제어하고 ListViewItem에서 image와 text 모두를 rendering 하는데 필요한 control들을 정의합니다. 여기 예제가 있습니다.

<Window x:Class="WpfTutorialSamples.ListView_control.ListViewBasicSample"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="ListViewBasicSample" Height="200" Width="200">
    <Grid>
		<ListView Margin="10">
			<ListViewItem>
				<StackPanel Orientation="Horizontal">
					<Image Source="/WpfTutorialSamples;component/Images/bullet_green.png" Margin="0,0,5,0" />
					<TextBlock>Green</TextBlock>
				</StackPanel>
			</ListViewItem>
			<ListViewItem>
				<StackPanel Orientation="Horizontal">
					<Image Source="/WpfTutorialSamples;component/Images/bullet_blue.png" Margin="0,0,5,0" />
					<TextBlock>Blue</TextBlock>
				</StackPanel>
			</ListViewItem>
			<ListViewItem IsSelected="True">
				<StackPanel Orientation="Horizontal">
					<Image Source="/WpfTutorialSamples;component/Images/bullet_red.png" Margin="0,0,5,0" />
					<TextBlock>Red</TextBlock>
				</StackPanel>
			</ListViewItem>
		</ListView>
	</Grid>
</Window>

우리가 이 예제에서 한 것은 매우 간단합니다. 그 이유는 ListViewItem이 ContentControl class로부터 파생되기 때문이며 우리는 그것의 content를 WPF control로 지정할 수 있습니다. 이 예제의 경우, 우리는 Image와 TextBlock을 자식 controls로 가지는 StackPanel을 사용했습니다.

요약

봤듯이, ListView를 XAML에서 수동으로 생성하는 것은 매우 간단합니다. 하지만 대부분의 경우 runtime에 Listview에 rendering 돼야 할 일종의 data source로부터 data를 받아올 것입니다. 우리는 다음 chapter에서 그렇게 하는 방법을 배워볼 것입니다.


This article has been fully translated into the following languages: Is your preferred language not on the list? Click here to help us translate this article into your language!
Table of Contents