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

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 엘리먼트 : 둥근 고리 모양의 Thumb을 갖는 Slider 엘리먼트 정의하기"
    Background="Black"
    FontFamily="나눔고딕코딩"
    FontSize="16">
    <Window.Resources>
        <SolidColorBrush x:Key="CustomSliderBackgroundSolidColorBrushKey" Color="#55ffffff" />
        <SolidColorBrush x:Key="CustomSliderForegroundSolidColorBrushKey" Color="#ff1e91ea" />
        <ControlTemplate x:Key="CustomSliderThumbControlTemplateKey" TargetType="{x:Type Thumb}">
            <Grid
                HorizontalAlignment="Center"
                UseLayoutRounding="True"
                VerticalAlignment="Center">
                <Path x:Name="gripPath"
                    VerticalAlignment="Center"
                    Margin="-1 -1"
                    Stretch="Fill"
                    Stroke="{StaticResource CustomSliderForegroundSolidColorBrushKey}"
                    StrokeThickness="2.5"
                    Fill="Transparent"
                    UseLayoutRounding="True"
                    Data="M 0 0 A 180 180 180 1 1 1 1 Z" />
            </Grid>
            <ControlTemplate.Triggers>
                <Trigger Property="IsDragging" Value="true">
                    <Setter
                        TargetName="gripPath"
                        Property="Fill"
                        Value="{StaticResource CustomSliderForegroundSolidColorBrushKey}" />
                    <Setter
                        TargetName="gripPath"
                        Property="Stroke"
                        Value="{StaticResource CustomSliderForegroundSolidColorBrushKey}" />
                </Trigger>
                <Trigger Property="IsEnabled" Value="false">
                    <Setter
                        TargetName="gripPath"
                        Property="Visibility"
                        Value="Hidden" />
                </Trigger>
                <Trigger Property="IsKeyboardFocused" Value="true">
                    <Setter
                        TargetName="gripPath"
                        Property="Fill"
                        Value="{StaticResource CustomSliderForegroundSolidColorBrushKey}" />
                </Trigger>
            </ControlTemplate.Triggers>
        </ControlTemplate>
        <ControlTemplate x:Key="CustomSliderControlTemplateKey" TargetType="{x:Type Slider}">
            <Border x:Name="border"
                Background="Transparent"
                SnapsToDevicePixels="True">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="{TemplateBinding MinHeight}" />
                    </Grid.RowDefinitions>
                    <DockPanel LastChildFill="True">
                        <Border x:Name="PART_SelectionRange"
                            Height="3"
                            ClipToBounds="True"
                            Visibility="Visible">
                            <Rectangle
                                Margin="10 0 -10 0"
                                RadiusX="1"
                                RadiusY="1"
                                Fill="{StaticResource CustomSliderForegroundSolidColorBrushKey}" />
                        </Border>
                        <Border
                            ClipToBounds="True"
                            Height="3"
                            Visibility="Visible">
                            <Rectangle
                                Margin="20 0 10 0"
                                RadiusX="1"
                                RadiusY="1"
                                Fill="{StaticResource CustomSliderBackgroundSolidColorBrushKey}" />
                        </Border>
                    </DockPanel>
                    <Track x:Name="PART_Track">
                        <Track.Thumb>
                            <Thumb x:Name="Thumb"
                                Template="{StaticResource CustomSliderThumbControlTemplateKey}"
                                VerticalAlignment="Center"
                                Width="{TemplateBinding MinHeight}"
                                Height="{TemplateBinding MinHeight}"
                                OverridesDefaultStyle="True"
                                Focusable="False" />
                        </Track.Thumb>
                    </Track>
                </Grid>
            </Border>
        </ControlTemplate>
        <Style x:Key="CustomSliderStyleKey" TargetType="{x:Type Slider}">
            <Setter Property="Template"                     Value="{StaticResource CustomSliderControlTemplateKey}"            />
            <Setter Property="VerticalAlignment"            Value="Center"                                                     />
            <Setter Property="MinHeight"                    Value="20"                                                         />
            <Setter Property="Height"                       Value="20"                                                         />
            <Setter Property="MaxHeight"                    Value="20"                                                         />
            <Setter Property="BorderBrush"                  Value="Transparent"                                                />
            <Setter Property="Background"                   Value="Transparent"                                                />
            <Setter Property="AutoToolTipPlacement"         Value="None"                                                       />
            <Setter Property="IsMoveToPointEnabled"         Value="True"                                                       />
            <Setter Property="Minimum"                      Value="0"                                                          />
            <Setter Property="SelectionStart"               Value="0"                                                          />
            <Setter Property="SelectionEnd"                 Value="{Binding Path=Value, RelativeSource={RelativeSource Self}}" />
            <Setter Property="Stylus.IsPressAndHoldEnabled" Value="false"                                                      />
        </Style>
    </Window.Resources>
    <Grid Margin="10">
        <Slider Name="slider"
            Style="{DynamicResource CustomSliderStyleKey}"
            Cursor="Hand"
            Minimum="0"
            Maximum="100" 
            SmallChange="10"
            LargeChange="20"
            Value="50" />
    </Grid>
</Window>
728x90
반응형
그리드형(광고전용)
Posted by 사용자 icodebroker
TAG , ,

댓글을 달아 주세요