첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
728x90
반응형
728x170

■ ControlTemplate 엘리먼트를 사용해 가로 방향의 ListBox 엘리먼트를 정의하는 방법을 보여준다.

TestProject.zip
다운로드

▶ MainWindow.xaml

<Window x:Class="TestProject.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Width="800"
    Height="600"
    Title="ControlTemplate 엘리먼트 : 가로 방향 ListBox 엘리먼트 정의하기"
    FontFamily="나눔고딕코딩"
    FontSize="16">
    <Window.Resources>
        <Style TargetType="ListBox">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ListBox">
                        <Border
                            CornerRadius="5"
                            Background="{TemplateBinding ListBox.Background}">
                            <ScrollViewer HorizontalScrollBarVisibility="Auto">
                                <StackPanel
                                    VerticalAlignment="Center"
                                    HorizontalAlignment="Center"
                                    Orientation="Horizontal"
                                    IsItemsHost="True" />
                            </ScrollViewer>
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </Window.Resources>
    <Grid>
        <ListBox
            Width="400"
            Height="50">
            <ListBoxItem>항목 1</ListBoxItem>
            <ListBoxItem>항목 2</ListBoxItem>
            <ListBoxItem>항목 3</ListBoxItem>
            <ListBoxItem>항목 4</ListBoxItem>
            <ListBoxItem>항목 5</ListBoxItem>
            <ListBoxItem>항목 6</ListBoxItem>
            <ListBoxItem>항목 7</ListBoxItem>
            <ListBoxItem>항목 8</ListBoxItem>
        </ListBox>
    </Grid>
</Window>

 

※ ControlTemplate 엘리먼트 내에서 StackPanel.IsItemHost 속성을 True로 설정하면 ListBox.ItemsPanel 속성 설정을 대체할 수 있다.

728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요