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

■ GradientBrush 클래스의 GradientStops 속성을 사용하는 방법을 보여준다.

TestProject.zip
0.01MB

▶ 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="TestProject"
    FontFamily="나눔고딕코딩"
    FontSize="16">
    <Window.Resources>
        <Style x:Key="AxisMarkerStyleKey">
            <Setter Property="Line.StrokeThickness"    Value="2"     />
            <Setter Property="Line.Stroke"             Value="Black" />
            <Setter Property="Line.StrokeDashArray"    Value="2 1"   />
            <Setter Property="Line.StrokeEndLineCap"   Value="Flat"  />
            <Setter Property="Line.StrokeStartLineCap" Value="Flat"  />
            <Style.Triggers>
                <EventTrigger RoutedEvent="Path.Loaded">
                    <BeginStoryboard>
                        <Storyboard>
                            <DoubleAnimation
                                Storyboard.TargetProperty="StrokeDashOffset"
                                Duration="00:00:01"
                                From="3"
                                To="0"
                                RepeatBehavior="Forever" />
                            </Storyboard>
                    </BeginStoryboard>
                </EventTrigger>
            </Style.Triggers>
        </Style>
        <Style x:Key="GradientMarkerStyleKey">
          <Setter Property="Path.StrokeThickness" Value="2"         />
          <Setter Property="Path.Stroke"          Value="Black"     />
          <Setter Property="Path.Fill"            Value="#99ffffff" />
        </Style>
        <Style TargetType="{x:Type Canvas}">
          <Setter Property="HorizontalAlignment" Value="Left" />
          <Setter Property="Margin"              Value="10"   />
        </Style>
    </Window.Resources>
    <Grid
        HorizontalAlignment="Center"
        VerticalAlignment="Center">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="20"   />
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="20"   />
            <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <Rectangle Grid.Row="0" Grid.Column="0"
            RadiusX="10"
            RadiusY="10"
            Fill="#773333cc"
            Margin="10" />
        <CheckBox Name="highlightGradientStopsCheckBox" Grid.Row="0" Grid.Column="0"
            Margin="20 10 10 10"
            Padding="10"
            IsChecked="True"
            VerticalContentAlignment="Center">
            Highlight Gradient Stops
        </CheckBox>
        <TextBlock Grid.Row="1" Grid.Column="0">Diagonal linear gradient</TextBlock>
        <Canvas Grid.Row="2" Grid.Column="0"
            Width="200"
            Height="100">
            <Rectangle
                Width="200"
                Height="100">
                <Rectangle.Fill>
                    <LinearGradientBrush
                        StartPoint="0 0"
                        EndPoint="1 1">
                        <GradientStop Offset="0"    Color="Yellow"    />
                        <GradientStop Offset="0.25" Color="Red"       />
                        <GradientStop Offset="0.75" Color="Blue"      />
                        <GradientStop Offset="1"    Color="LimeGreen" />
                    </LinearGradientBrush>
                </Rectangle.Fill>
            </Rectangle>
            <Line Name="gradientLine1"
                Style="{StaticResource AxisMarkerStyleKey}"
                X1="1"
                Y1="1"
                X2="199"
                Y2="99" />
            <Path Name="gradientPath1"
                Style="{StaticResource GradientMarkerStyleKey}">
                <Path.Data>
                    <GeometryGroup>
                        <EllipseGeometry Center="  0   0" RadiusX="4" RadiusY="4" />
                        <EllipseGeometry Center=" 50  25" RadiusX="4" RadiusY="4" />
                        <EllipseGeometry Center="150  75" RadiusX="4" RadiusY="4" />
                        <EllipseGeometry Center="200 100" RadiusX="4" RadiusY="4" />
                    </GeometryGroup>
                </Path.Data>
            </Path>
        </Canvas>
        <TextBlock Grid.Row="1" Grid.Column="2">Horizontal linear gradient</TextBlock>
        <Canvas Grid.Row="2" Grid.Column="2"
            Width="200"
            Height="100">
            <Rectangle
                Width="200"
                Height="100">
                <Rectangle.Fill>
                    <LinearGradientBrush
                        StartPoint="0 0.5"
                        EndPoint="1 0.5">
                        <GradientStop Offset="0"    Color="Yellow"    />
                        <GradientStop Offset="0.25" Color="Red"       />
                        <GradientStop Offset="0.75" Color="Blue"      />
                        <GradientStop Offset="1"    Color="LimeGreen" />
                    </LinearGradientBrush>
                </Rectangle.Fill>
            </Rectangle>
            <Line Name="gradientLine2"
                Style="{StaticResource AxisMarkerStyleKey}"
                X1="1"
                Y1="50"
                X2="199"
                Y2="50" />
            <Path Name="gradientPath2"
                Style="{StaticResource GradientMarkerStyleKey}">
                <Path.Data>
                    <GeometryGroup>
                        <EllipseGeometry Center="  0 50" RadiusX="4" RadiusY="4" />
                        <EllipseGeometry Center=" 50 50" RadiusX="4" RadiusY="4" />
                        <EllipseGeometry Center="150 50" RadiusX="4" RadiusY="4" />
                        <EllipseGeometry Center="200 50" RadiusX="4" RadiusY="4" />
                    </GeometryGroup>
                </Path.Data>
            </Path>
        </Canvas>
        <TextBlock Grid.Row="1" Grid.Column="4">Condensed horizontal gradient</TextBlock>
        <Canvas Grid.Row="2" Grid.Column="4"
            Width="200"
            Height="100">
            <Rectangle
                Width="200"
                Height="100">
                <Rectangle.Fill>
                    <LinearGradientBrush
                        StartPoint="0.25 0.5"
                        EndPoint="0.75 0.5">
                        <LinearGradientBrush.GradientStops>
                            <GradientStop Offset="0"    Color="Yellow"    />
                            <GradientStop Offset="0.25" Color="Red"       />
                            <GradientStop Offset="0.75" Color="Blue"      />
                            <GradientStop Offset="1"    Color="LimeGreen" />
                        </LinearGradientBrush.GradientStops>
                    </LinearGradientBrush>
                </Rectangle.Fill>
            </Rectangle>
            <Line Name="gradientLine3"
                Style="{StaticResource AxisMarkerStyleKey}"
                X1="49"
                Y1="50"
                X2="149"
                Y2="50" />
            <Path Name="gradientPath3"
                Style="{StaticResource GradientMarkerStyleKey}">
                <Path.Data>
                    <GeometryGroup>
                        <EllipseGeometry Center=" 50 50" RadiusX="4" RadiusY="4" />
                        <EllipseGeometry Center=" 75 50" RadiusX="4" RadiusY="4" />
                        <EllipseGeometry Center="125 50" RadiusX="4" RadiusY="4" />
                        <EllipseGeometry Center="150 50" RadiusX="4" RadiusY="4" />
                    </GeometryGroup>
                </Path.Data>
            </Path>
        </Canvas>
        <TextBlock Grid.Row="3" Grid.Column="0">Vertical linear gradient</TextBlock>
        <Canvas Grid.Row="4" Grid.Column="0"
            Width="200"
            Height="100">
            <Rectangle
                Width="200"
                Height="100">
                <Rectangle.Fill>
                    <LinearGradientBrush
                        StartPoint="0.5 0"
                        EndPoint="0.5 1">
                        <LinearGradientBrush.GradientStops>
                            <GradientStop Offset="0"    Color="Yellow"    />
                            <GradientStop Offset="0.25" Color="Red"       />
                            <GradientStop Offset="0.75" Color="Blue"      />
                            <GradientStop Offset="1"    Color="LimeGreen" />
                        </LinearGradientBrush.GradientStops>
                    </LinearGradientBrush>
                </Rectangle.Fill>
            </Rectangle>
            <Line Name="gradientLine4"
                Style="{StaticResource AxisMarkerStyleKey}"
                X1="100"
                Y1="1"
                X2="100"
                Y2="99" />
            <Path Name="gradientPath4"
                Style="{StaticResource GradientMarkerStyleKey}">
                <Path.Data>
                    <GeometryGroup>
                        <EllipseGeometry Center="100   0" RadiusX="4" RadiusY="4" />
                        <EllipseGeometry Center="100  25" RadiusX="4" RadiusY="4" />
                        <EllipseGeometry Center="100  75" RadiusX="4" RadiusY="4" />
                        <EllipseGeometry Center="100 100" RadiusX="4" RadiusY="4" />
                    </GeometryGroup>
                </Path.Data>
            </Path>
        </Canvas>
        <TextBlock Grid.Row="3" Grid.Column="2">Radial gradient</TextBlock>
        <Canvas Grid.Row="4" Grid.Column="2"
            Width="200"
            Height="100">
            <Rectangle
                Width="200"
                Height="100">
                <Rectangle.Fill>
                    <RadialGradientBrush
                        RadiusX="0.5"
                        RadiusY="0.5"
                        Center="0.5 0.5"
                        GradientOrigin="0.5 0.5">
                        <RadialGradientBrush.GradientStops>
                            <GradientStop Offset="0"    Color="Yellow"    />
                            <GradientStop Offset="0.25" Color="Red"       />
                            <GradientStop Offset="0.75" Color="Blue"      />
                            <GradientStop Offset="1"    Color="LimeGreen" />
                        </RadialGradientBrush.GradientStops>
                    </RadialGradientBrush>
                </Rectangle.Fill>
            </Rectangle>
            <Line Name="gradientLine5"
                Style="{StaticResource AxisMarkerStyleKey}"
                X1="101"
                Y1="50"
                X2="199"
                Y2="50" />
            <Path Name="gradientPath5"
                Style="{StaticResource GradientMarkerStyleKey}">
                <Path.Data>
                    <GeometryGroup>
                        <EllipseGeometry Center="100 50" RadiusX="4" RadiusY="4" />
                        <EllipseGeometry Center="125 50" RadiusX="4" RadiusY="4" />
                        <EllipseGeometry Center="175 50" RadiusX="4" RadiusY="4" />
                        <EllipseGeometry Center="200 50" RadiusX="4" RadiusY="4" />
                    </GeometryGroup>
                </Path.Data>
            </Path>
        </Canvas>
    </Grid>
</Window>

 

▶ MainWindow.xaml.cs

using System.Windows;

namespace TestProject
{
    /// <summary>
    /// 메인 윈도우
    /// </summary>
    public partial class MainWindow : Window
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 생성자 - MainWindow()

        /// <summary>
        /// 생성자
        /// </summary>
        public MainWindow()
        {
            InitializeComponent();

            Loaded += Window_Loaded;
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 윈도우 로드시 처리하기 - Window_Loaded(sender, e)

        /// <summary>
        /// 윈도우 로드시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            this.highlightGradientStopsCheckBox.Checked   += highlightGradientStopsCheckBox_Checked;
            this.highlightGradientStopsCheckBox.Unchecked += highlightGradientStopsCheckBox_Unchecked;
        }

        #endregion

        #region Highlight Gradient Stops 체크 박스 체크시 처리하기 - highlightGradientStopsCheckBox_Checked(sender, e)

        /// <summary>
        /// Highlight Gradient Stops 체크 박스 체크시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void highlightGradientStopsCheckBox_Checked(object sender, RoutedEventArgs e)
        {
            this.gradientLine1.Opacity = 1.0;
            this.gradientLine2.Opacity = 1.0;
            this.gradientLine3.Opacity = 1.0;
            this.gradientLine4.Opacity = 1.0;
            this.gradientLine5.Opacity = 1.0;

            this.gradientPath1.Opacity = 1.0;
            this.gradientPath2.Opacity = 1.0;
            this.gradientPath3.Opacity = 1.0;
            this.gradientPath4.Opacity = 1.0;
            this.gradientPath5.Opacity = 1.0;
        }

        #endregion
        #region Highlight Gradient Stops 체크 박스 체크 해제시 처리하기 - highlightGradientStopsCheckBox_Unchecked(sender, e)

        /// <summary>
        /// Highlight Gradient Stops 체크 박스 체크 해제시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void highlightGradientStopsCheckBox_Unchecked(object sender, RoutedEventArgs e)
        {
            this.gradientLine1.Opacity = 0.0;
            this.gradientLine2.Opacity = 0.0;
            this.gradientLine3.Opacity = 0.0;
            this.gradientLine4.Opacity = 0.0;
            this.gradientLine5.Opacity = 0.0;

            this.gradientPath1.Opacity = 0.0;
            this.gradientPath2.Opacity = 0.0;
            this.gradientPath3.Opacity = 0.0;
            this.gradientPath4.Opacity = 0.0;
            this.gradientPath5.Opacity = 0.0;
        }

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

댓글을 달아 주세요