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

■ DropShadowBitmapEffect 클래스를 사용해 버튼 클릭시 그림자 효과를 적용하는 방법을 보여준다.

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="DropShadowBitmapEffect 클래스 : 버튼 클릭시 그림자 효과 적용하기"
    FontFamily="나눔고딕코딩"
    FontSize="16">
    <Grid>
        <Button Name="button"
            Width="100"
            Height="30"
            Content="테스트" />
    </Grid>
</Window>

 

▶ MainWindow.xaml.cs

using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Effects;

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

        #region 생성자 - MainWindow()

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

            this.button.Click += button_Click;
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region 테스트 버튼 클릭시 처리하기 - button_Click(sender, e)

        /// <summary>
        /// 테스트 버튼 클릭시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void button_Click(object sender, RoutedEventArgs e)
        {
            Button button = sender as Button;

            DropShadowBitmapEffect effect = new DropShadowBitmapEffect();

            Color color = new Color();

            color.ScA = 1;
            color.ScB = 0;
            color.ScG = 0;
            color.ScR = 0;

            effect.Color       = color;
            effect.Direction   = 320;
            effect.ShadowDepth = 25;
            effect.Softness    = 1;
            effect.Opacity     = 0.5;

            button.BitmapEffect = effect;
        }

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