첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
본 블로그는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 블로그 콘텐츠 향상을 위해 쓰여집니다.

728x90
반응형
728x170

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 엘리먼트 : ScrollViewer 엘리먼트 정의하기"
    Background="Black"
    Foreground="White"
    FontFamily="나눔고딕코딩"
    FontSize="16">
    <Window.Resources>
        <Style x:Key="ScrollBarThumbKey" TargetType="{x:Type Thumb}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Thumb}">
                        <Grid x:Name="grid">
                            <Rectangle
                                HorizontalAlignment="Stretch"
                                VerticalAlignment="Stretch"
                                Width="Auto"
                                Height="Auto"
                                Fill="Transparent" />
                            <Border x:Name="rectangle"
                                HorizontalAlignment="Stretch"
                                VerticalAlignment="Stretch"
                                Width="Auto"
                                Height="Auto"
                                CornerRadius="5"
                                Background="{TemplateBinding Background}" />
                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="Tag" Value="Horizontal">
                                <Setter
                                    TargetName="rectangle"
                                    Property="Width"
                                    Value="Auto" />
                                <Setter
                                    TargetName="rectangle"
                                    Property="Height"
                                    Value="7" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <Style x:Key="{x:Type ScrollBar}" TargetType="{x:Type ScrollBar}">
            <Setter Property="Width"                  Value="8"           />
            <Setter Property="Background"             Value="Transparent" />
            <Setter Property="Foreground"             Value="#8c8c8c"     />
            <Setter Property="Stylus.IsFlicksEnabled" Value="false"       />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ScrollBar}">
                        <Grid x:Name="rootGrid"
                            Width="8"
                            Background="{TemplateBinding Background}">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="0.00001*" />
                            </Grid.RowDefinitions>
                            <Track x:Name="PART_Track" Grid.Row="0"
                                IsDirectionReversed="true"
                                Focusable="false">
                                <Track.Thumb>
                                    <Thumb x:Name="thumb"
                                        Style="{DynamicResource ScrollBarThumbKey}"
                                        Background="{TemplateBinding Foreground}" />
                                </Track.Thumb>
                                <Track.IncreaseRepeatButton>
                                    <RepeatButton x:Name="pageUpButton"
                                        Opacity="0"
                                        Focusable="false"
                                        Command="ScrollBar.PageDownCommand" />
                                </Track.IncreaseRepeatButton>
                                <Track.DecreaseRepeatButton>
                                    <RepeatButton x:Name="pageDownButton"
                                        Opacity="0"
                                        Focusable="false"
                                        Command="ScrollBar.PageUpCommand" />
                                </Track.DecreaseRepeatButton>
                            </Track>
                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger SourceName="thumb" Property="IsMouseOver" Value="true">
                                <Setter
                                    TargetName="thumb"
                                    Property="Background"
                                    Value="{DynamicResource ButtonSelectBrush}" />
                            </Trigger>
                            <Trigger SourceName="thumb" Property="IsDragging" Value="true">
                                <Setter
                                    TargetName="thumb"
                                    Property="Background"
                                    Value="{DynamicResource DarkBrush}" />
                            </Trigger>
                            <Trigger Property="IsEnabled" Value="false">
                                <Setter
                                    TargetName="thumb"
                                    Property="Visibility"
                                    Value="Collapsed" />
                            </Trigger>
                            <Trigger Property="Orientation" Value="Horizontal">
                                <Setter
                                    TargetName="rootGrid"
                                    Property="LayoutTransform">
                                    <Setter.Value>
                                        <RotateTransform Angle="-90" />
                                    </Setter.Value>
                                </Setter>
                                <Setter
                                    TargetName="PART_Track"
                                    Property="LayoutTransform">
                                    <Setter.Value>
                                        <RotateTransform Angle="-90" />
                                    </Setter.Value>
                                </Setter>
                                <Setter Property="Width"  Value="Auto" />
                                <Setter Property="Height" Value="8"    />
                                <Setter
                                    TargetName="thumb"
                                    Property="Tag"
                                    Value="Horizontal" />
                                <Setter
                                    TargetName="pageDownButton"
                                    Property="Command"
                                    Value="ScrollBar.PageLeftCommand" />
                                <Setter
                                    TargetName="pageUpButton"
                                    Property="Command"
                                    Value="ScrollBar.PageRightCommand" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </Window.Resources>
    <Grid Margin="10">
        <ScrollViewer
            VerticalScrollBarVisibility="Auto"
            HorizontalScrollBarVisibility="Auto"
            Height="{Binding Path=ActualHeight, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=UIElement}}">
            <StackPanel>
                <TextBlock Margin="10" Text="테스트 문자열 입니다." />
                <TextBlock Margin="10" Text="테스트 문자열 입니다." />
                <TextBlock Margin="10" Text="테스트 문자열 입니다." />
                <TextBlock Margin="10" Text="테스트 문자열 입니다." />
                <TextBlock Margin="10" Text="테스트 문자열 입니다." />
                <TextBlock Margin="10" Text="테스트 문자열 입니다." />
                <TextBlock Margin="10" Text="테스트 문자열 입니다." />
                <TextBlock Margin="10" Text="테스트 문자열 입니다." />
                <TextBlock Margin="10" Text="테스트 문자열 입니다." />
                <TextBlock Margin="10" Text="테스트 문자열 입니다." />
                <TextBlock Margin="10" Text="테스트 문자열 입니다." />
                <TextBlock Margin="10" Text="테스트 문자열 입니다." />
                <TextBlock Margin="10" Text="테스트 문자열 입니다." />
                <TextBlock Margin="10" Text="테스트 문자열 입니다." />
                <TextBlock Margin="10" Text="테스트 문자열 입니다." />
                <TextBlock Margin="10" Text="테스트 문자열 입니다." />
                <TextBlock Margin="10" Text="테스트 문자열 입니다." />
                <TextBlock Margin="10" Text="테스트 문자열 입니다." />
                <TextBlock Margin="10" Text="테스트 문자열 입니다." />
                <TextBlock Margin="10" Text="테스트 문자열 입니다." />
            </StackPanel>
        </ScrollViewer>
    </Grid>
</Window>
728x90
반응형
그리드형(광고전용)
Posted by 사용자 icodebroker
TAG , ,

댓글을 달아 주세요