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

TestProject.zip
3.98MB

▶ ColorHelper.cs

using System;
using System.Windows.Media;

namespace TestProject
{
    /// <summary>
    /// 색상 헬퍼
    /// </summary>
    public static class ColorHelper
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Static
        //////////////////////////////////////////////////////////////////////////////// Public

        #region 단일 색상 브러시 구하기 - GetSolidColorBrush(solidColorBrush, strength)

        /// <summary>
        /// 단일 색상 브러시 구하기
        /// </summary>
        /// <param name="solidColorBrush">단일 색상 브러시</param>
        /// <param name="strength">강도</param>
        /// <returns>단일 색상 브러시</returns>
        public static SolidColorBrush GetSolidColorBrush(this SolidColorBrush solidColorBrush, byte strength = 191)
        {
            Color color = solidColorBrush.Color;

            color.A = strength == 0 ? (byte)1 : strength;

            return new SolidColorBrush(color);
        }

        #endregion
        #region 단일 색상 브러시 구하기 - GetSolidColorBrush(solidColorBrush, strength)

        /// <summary>
        /// 단일 색상 브러시 구하기
        /// </summary>
        /// <param name="solidColorBrush">단일 색상 브러시</param>
        /// <param name="strength">강도</param>
        /// <returns>단일 색상 브러시</returns>
        public static SolidColorBrush GetSolidColorBrush(this SolidColorBrush solidColorBrush, double strength = 0.75d)
        {
            if(strength < 0d || strength > 1.0d)
            {
                throw new ArgumentOutOfRangeException(nameof(strength), @"strength must be a value between 0.0 and 1.0");
            }

            return solidColorBrush.GetSolidColorBrush((byte)(strength * 255));
        }

        #endregion
        #region 단일 색상 브러시 구하기 - GetSolidColorBrush(color)

        /// <summary>
        /// 단일 색상 브러시 구하기
        /// </summary>
        /// <param name="color">색상</param>
        /// <returns>단일 색상 브러시</returns>
        public static SolidColorBrush GetSolidColorBrush(this Color color)
        {
            return new SolidColorBrush(color);
        }

        #endregion
        #region 단일 색상 브러시 구하기 - GetSolidColorBrush(brush, strength)

        /// <summary>
        /// 단일 색상 브러시 구하기
        /// </summary>
        /// <param name="brush">브러시</param>
        /// <param name="strength">강도</param>
        /// <returns>단일 색상 브러시</returns>
        public static SolidColorBrush GetSolidColorBrush(this Brush brush, double strength = 0.75d)
        {
            if(strength < 0d || strength > 1d)
            {
                throw new ArgumentOutOfRangeException(nameof(strength), @"strength must be a value between 0.0 and 1.0");
            }

            return ((SolidColorBrush)brush).GetSolidColorBrush((byte)(strength * 255));
        }

        #endregion
        #region 단일 색상 브러시 구하기 - GetSolidColorBrush(color, strength)

        /// <summary>
        /// 단일 색상 브러시 구하기
        /// </summary>
        /// <param name="color">색상</param>
        /// <param name="strength">강도</param>
        /// <returns>단일 색상 브러시</returns>
        public static SolidColorBrush GetSolidColorBrush(this Color color, double strength = 0.75d)
        {
            if(strength < 0d || strength > 1d)
            {
                throw new ArgumentOutOfRangeException(nameof(strength), @"strength must be a value between 0.0 and 1.0");
            }

            return GetSolidColorBrush(new SolidColorBrush(color), (byte)(strength * 255));
        }

        #endregion
    }
}

 

728x90

 

▶ CursorHelper.cs

using System;
using System.Windows;
using System.Windows.Input;

namespace TestProject
{
    /// <summary>
    /// 커서 헬퍼
    /// </summary>
    public static class CursorHelper
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Static
        //////////////////////////////////////////////////////////////////////////////// Public

        #region 커서 구하기 - GetCursor(cursor)

        /// <summary>
        /// 커서 구하기
        /// </summary>
        /// <param name="cursor">드래그 커서</param>
        /// <returns>커서</returns>
        public static Cursor GetCursor(this DragCursor cursor)
        {
            switch(cursor)
            {
                case DragCursor.Grab :
                
                    return new Cursor
                    (
                        Application.GetResourceStream
                        (
                            new Uri("pack://application:,,,/TestProject;component/CURSOR/grab.cur")
                        )?.Stream ?? throw new InvalidOperationException()
                    );

                case DragCursor.Grabbing :
                
                    return new Cursor
                    (
                        Application.GetResourceStream
                        (
                            new Uri("pack://application:,,,/TestProject;component/CURSOR/grabbing.cur")
                        )?.Stream ?? throw new InvalidOperationException()
                    );

                default :
                
                    throw new ArgumentOutOfRangeException(nameof(cursor), cursor, null);
            }
        }

        #endregion
    }
}

 

300x250

 

▶ GlassControl.xaml

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:TestProject">
    <Style TargetType="{x:Type local:GlassControl}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:GlassControl}">
                    <Border
                        BorderBrush="{TemplateBinding BorderBrush}"
                        BorderThickness="{TemplateBinding BorderThickness}">
                        <Grid ClipToBounds="True">
                            <Rectangle x:Name="Blur"
                                Width="{Binding ActualWidth, RelativeSource={RelativeSource AncestorType={x:Type local:GlassControl}}}"
                                Height="{Binding ActualHeight, RelativeSource={RelativeSource AncestorType={x:Type local:GlassControl}}}" />
                            <Rectangle Fill="{TemplateBinding Background}" />
                            <AdornerDecorator>
                                <ContentPresenter />
                            </AdornerDecorator>
                        </Grid>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>

 

▶ Generic.xaml

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="pack://application:,,,/TestProject;component/THEMES/GlassControl.xaml" />
    </ResourceDictionary.MergedDictionaries>
</ResourceDictionary>

 

▶ DragCursor.cs

namespace TestProject
{
    /// <summary>
    /// 드래그 커서
    /// </summary>
    public enum DragCursor
    {
        /// <summary>
        /// Grab
        /// </summary>
        Grab,

        /// <summary>
        /// Grabbing
        /// </summary>
        Grabbing
    }
}

 

▶ GlassControl.cs

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Effects;
using System.Windows.Shapes;

namespace TestProject
{
    /// <summary>
    /// 글래스 컨트롤
    /// </summary>
    public class GlassControl : UserControl
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Field
        ////////////////////////////////////////////////////////////////////////////////////////// Static
        //////////////////////////////////////////////////////////////////////////////// Public

        #region Field

        /// <summary>
        /// BLUR 컨테이너 속성
        /// </summary>
        public static readonly DependencyProperty BlurContainerProperty = DependencyProperty.Register
        (
            "BlurContainer",
            typeof(UIElement),
            typeof(GlassControl),
            new PropertyMetadata(default(UIElement), BlurContainerPropertyChangedCallback)
        );

        /// <summary>
        /// BLUR 반경 속성
        /// </summary>
        public static readonly DependencyProperty BlurRadiusProperty = DependencyProperty.Register
        (
            "BlurRadius",
            typeof(int),
            typeof(GlassControl),
            new PropertyMetadata(10, BlurRadiusPropertyChangedCallback)
        );

        /// <summary>
        /// 렌더링 바이어스 속성
        /// </summary>
        public static readonly DependencyProperty RenderingBiasProperty = DependencyProperty.Register
        (
            "RenderingBias",
            typeof(RenderingBias),
            typeof(GlassControl),
            new PropertyMetadata(RenderingBias.Quality, RenderingBiasPropertyChangedCallback)
        );

        /// <summary>
        /// 확대 속성
        /// </summary>
        public static readonly DependencyProperty MagnificationProperty = DependencyProperty.Register
        (
            "Magnification",
            typeof(double),
            typeof(GlassControl),
            new PropertyMetadata(1.0d, MagnificationPropertyChangedCallback)
        );

        /// <summary>
        /// 브러시 속성
        /// </summary>
        private static readonly DependencyProperty BrushProperty = DependencyProperty.Register
        (
            "Brush",
            typeof(VisualBrush),
            typeof(GlassControl),
            new PropertyMetadata()
        );

        /// <summary>
        /// 드래그 이동 이용 가능 여부 속성
        /// </summary>
        public static readonly DependencyProperty DragMoveEnabledProperty = DependencyProperty.Register
        (
            "DragMoveEnabled",
            typeof(bool),
            typeof(GlassControl),
            new PropertyMetadata(false, DragMoveEnabledPropertyChangedCallback)
        );

        #endregion

        ////////////////////////////////////////////////////////////////////////////////////////// Instance
        //////////////////////////////////////////////////////////////////////////////// Private

        #region Field

        /// <summary>
        /// BLUR 사각형
        /// </summary>
        private Rectangle blurRectangle;

        /// <summary>
        /// 드래그 여부
        /// </summary>
        private bool isDragging;

        /// <summary>
        /// 앵커 포인트
        /// </summary>
        private Point anchorPoint;

        /// <summary>
        /// 컨테이너 크기
        /// </summary>
        private Size containerSize;

        /// <summary>
        /// 차이 포인트
        /// </summary>
        private Point differencePoint;

        /// <summary>
        /// 스케일 X
        /// </summary>
        private double scaleX;

        /// <summary>
        /// 스케일 Y
        /// </summary>
        private double scaleY;
        
        /// <summary>
        /// UGLY 커서 표시 여부
        /// </summary>
        private const bool SHOW_UGLY_CURSOR = false;

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Property
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region BLUR 컨테이너 - BlurContainer

        /// <summary>
        /// BLUR 컨테이너
        /// </summary>
        public UIElement BlurContainer
        {
            get => (UIElement)GetValue(BlurContainerProperty);
            set => SetValue(BlurContainerProperty, value);
        }

        #endregion
        #region BLUR 반경 - BlurRadius

        /// <summary>
        /// BLUR 반경
        /// </summary>
        public int BlurRadius
        {
            get =>(int)GetValue(BlurRadiusProperty);
            set => SetValue(BlurRadiusProperty, value);
        }

        #endregion
        #region 렌더링 바이어스 - RenderingBias

        /// <summary>
        /// 렌더링 바이어스
        /// </summary>
        public RenderingBias RenderingBias
        {
            get => (RenderingBias)GetValue(RenderingBiasProperty);
            set => SetValue(RenderingBiasProperty, value);
        }

        #endregion
        #region 확대 - Magnification

        /// <summary>
        /// 확대
        /// </summary>
        public double Magnification
        {
            get => (double)GetValue(MagnificationProperty);
            set => SetValue(MagnificationProperty, value);
        }

        #endregion
        #region 브러시 - Brush

        /// <summary>
        /// 브러시
        /// </summary>
        private VisualBrush Brush
        {
            get => (VisualBrush)GetValue(BrushProperty);
            set => SetValue(BrushProperty, value);
        }

        #endregion
        #region 드래그 이동 이용 가능 여부 - DragMoveEnabled

        /// <summary>
        /// 드래그 이동 이용 가능 여부
        /// </summary>
        public bool DragMoveEnabled
        {
            get => (bool)GetValue(DragMoveEnabledProperty);
            set => SetValue(DragMoveEnabledProperty, value);
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
        ////////////////////////////////////////////////////////////////////////////////////////// Static

        #region 생성자 - GlassControl()

        /// <summary>
        /// 생성자
        /// </summary>
        static GlassControl()
        {
            DefaultStyleKeyProperty.OverrideMetadata
            (
                typeof(GlassControl),
                new FrameworkPropertyMetadata(typeof(GlassControl))
            );
        }

        #endregion

        ////////////////////////////////////////////////////////////////////////////////////////// Instance
        //////////////////////////////////////////////////////////////////////////////// Public

        #region 생성자 - GlassControl()

        /// <summary>
        /// 생성자
        /// </summary>
        public GlassControl()
        {
            Loaded += UserControl_Loaded;

            Background = Brushes.WhiteSmoke.GetSolidColorBrush(0.2d);
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Static
        //////////////////////////////////////////////////////////////////////////////// Private

        #region BLUR 컨테이너 속성 변경시 콜백 처리하기 - BlurContainerPropertyChangedCallback(d, e)

        /// <summary>
        /// BLUR 컨테이너 속성 변경시 콜백 처리하기
        /// </summary>
        /// <param name="d">의존 객체</param>
        /// <param name="e">이벤트 인자</param>
        private static void BlurContainerPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            GlassControl userControl = d as GlassControl;

            userControl.UpdateVisual(e.OldValue as UIElement);
        }

        #endregion
        #region BLUR 반경 속성 변경시 콜백 처리하기 - BlurRadiusPropertyChangedCallback(d, e)

        /// <summary>
        /// BLUR 반경 속성 변경시 콜백 처리하기
        /// </summary>
        /// <param name="d">의존 객체</param>
        /// <param name="e">이벤트 인자</param>
        private static void BlurRadiusPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            GlassControl userControl = d as GlassControl;

            userControl.UpdateVisual();
        }

        #endregion
        #region 렌더링 바이어스 속성 변경시 콜백 처리하기 - RenderingBiasPropertyChangedCallback(d, e)

        /// <summary>
        /// 렌더링 바이어스 속성 변경시 콜백 처리하기
        /// </summary>
        /// <param name="d">의존 객체</param>
        /// <param name="e">이벤트 인자</param>
        private static void RenderingBiasPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            GlassControl userControl = d as GlassControl;

            userControl.UpdateVisual();
        }

        #endregion
        #region 확대 속성 변경시 콜백 처리하기 - MagnificationPropertyChangedCallback(d, e)

        /// <summary>
        /// 확대 속성 변경시 콜백 처리하기
        /// </summary>
        /// <param name="d">의존 객체</param>
        /// <param name="e">이벤트 인자</param>
        private static void MagnificationPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            GlassControl userControl = d as GlassControl;

            userControl.UpdateVisual();
        }

        #endregion
        #region 드래그 이동 이용 가능 여부 속성 변경시 콜백 처리하기 - DragMoveEnabledPropertyChangedCallback(d, e)

        /// <summary>
        /// 드래그 이동 이용 가능 여부 속성 변경시 콜백 처리하기
        /// </summary>
        /// <param name="d">의존 객체</param>
        /// <param name="e">이벤트 인자</param>
        private static void DragMoveEnabledPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            GlassControl userControl = d as GlassControl;

            if((bool)e.NewValue)
            {
                userControl.AddMouseEventHandler();
            }
            else
            {
                userControl.RemoveMouseEventHandler();
            }
        }

        #endregion

        ////////////////////////////////////////////////////////////////////////////////////////// Instance
        //////////////////////////////////////////////////////////////////////////////// Public

        #region 템플리트 적용시 처리하기 - OnApplyTemplate()

        /// <summary>
        /// 템플리트 적용시 처리하기
        /// </summary>
        public override void OnApplyTemplate()
        {
            this.blurRectangle = (Rectangle) GetTemplateChild("Blur");

            this.blurRectangle?.SetBinding
            (
                Shape.FillProperty,
                new Binding { Source = this, Path = new PropertyPath(BrushProperty) }
            );

            base.OnApplyTemplate();
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////// Private
        ////////////////////////////////////////////////////////////////////// Event

        #region 사용자 컨트롤 로드시 처리하기 - UserControl_Loaded(sender, e)

        /// <summary>
        /// 사용자 컨트롤 로드시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            UpdateVisual();

            if(DragMoveEnabled)
            {
                AddMouseEventHandler();
            }
            else
            {
                RemoveMouseEventHandler();
            }
        }

        #endregion
        #region 사용자 컨트롤 마우스 ENTER 처리하기 - UserControl_MouseEnter(sender, e)

        /// <summary>
        /// 사용자 컨트롤 마우스 ENTER 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void UserControl_MouseEnter(object sender, MouseEventArgs e)
        {
#pragma warning disable 162
            if(SHOW_UGLY_CURSOR)
            {
                Cursor = DragCursor.Grab.GetCursor();
            }
#pragma warning restore 162
        }

        #endregion
        #region 사용자 컨트롤 마우스 이동시 처리하기 - UserControl_MouseMove(sender, e)

        /// <summary>
        /// 사용자 컨트롤 마우스 이동시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void UserControl_MouseMove(object sender, MouseEventArgs e)
        {
            if(!this.isDragging)
            {
                return;
            }

            Point currentPoint = e.GetPosition(null);

            TranslateTransform currentTranslateTransform = RenderTransform as TranslateTransform ?? new TranslateTransform(0, 0);

            Vector movementVector = currentPoint - this.anchorPoint;

            double newX       = currentTranslateTransform.X + movementVector.X;
            double maximumX   = this.containerSize.Width - Width + BorderThickness.Right;
            double thresholdX = this.differencePoint.X + movementVector.X + BlurRadius * Magnification;

            double newY       = currentTranslateTransform.Y + movementVector.Y;
            double maximumY   = this.containerSize.Height - Height + BorderThickness.Bottom;
            double thresholdY = this.differencePoint.Y + movementVector.Y + BlurRadius * Magnification;

            double left = thresholdX > BorderThickness.Left ? thresholdX < maximumX ? newX : currentTranslateTransform.X : currentTranslateTransform.X;
            double top  = thresholdY > BorderThickness.Top  ? thresholdY < maximumY ? newY : currentTranslateTransform.Y : currentTranslateTransform.Y;

            RenderTransform = new TranslateTransform(left, top);

            this.anchorPoint = currentPoint;

            e.Handled = true;
        }

        #endregion
        #region 사용자 컨트롤 마우스 왼쪽 버튼 DOWN 처리하기 - UserControl_MouseLeftButtonDown(sender, e)

        /// <summary>
        /// 사용자 컨트롤 마우스 왼쪽 버튼 DOWN 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void UserControl_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            if(this.isDragging)
            {
                return;
            }

            this.anchorPoint = e.GetPosition(null);

            CaptureMouse();

            this.isDragging = true;

            e.Handled = true;

#pragma warning disable 162
            if(SHOW_UGLY_CURSOR)
            {
                Cursor = DragCursor.Grabbing.GetCursor();
            }
#pragma warning restore 162
        }

        #endregion
        #region 사용자 컨트롤 마우스 왼쪽 버튼 UP 처리하기 - UserControl_MouseLeftButtonUp(sender, e)

        /// <summary>
        /// 사용자 컨트롤 마우스 왼쪽 버튼 UP 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void UserControl_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            if(!this.isDragging)
            {
                return;
            }

            ReleaseMouseCapture();

            this.isDragging = false;

            e.Handled = true;

#pragma warning disable 162
            if(SHOW_UGLY_CURSOR)
            {
                Cursor = DragCursor.Grab.GetCursor();
            }
#pragma warning restore 162
        }

        #endregion

        #region BLUR 컨테이너 레이아웃 업데이트시 처리하기 - blurContainer_LayoutUpdated(sender, e)

        /// <summary>
        /// BLUR 컨테이너 레이아웃 업데이트시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void blurContainer_LayoutUpdated(object sender, EventArgs e)
        {
            RefreshBoundRectangle();
        }

        #endregion

        ////////////////////////////////////////////////////////////////////// Function

        #region 마우스 이벤트 핸들러 추가하기 - AddMouseEventHandler()

        /// <summary>
        /// 마우스 이벤트 핸들러 추가하기
        /// </summary>
        private void AddMouseEventHandler()
        {
            MouseEnter          += UserControl_MouseEnter;
            MouseMove           += UserControl_MouseMove;
            MouseLeftButtonDown += UserControl_MouseLeftButtonDown;
            MouseLeftButtonUp   += UserControl_MouseLeftButtonUp;
        }

        #endregion
        #region 마우스 이벤트 핸들러 제거하기 - RemoveMouseEventHandler()

        /// <summary>
        /// 마우스 이벤트 핸들러 제거하기
        /// </summary>
        private void RemoveMouseEventHandler()
        {
            MouseEnter          -= UserControl_MouseEnter;
            MouseMove           -= UserControl_MouseMove;
            MouseLeftButtonDown -= UserControl_MouseLeftButtonDown;
            MouseLeftButtonUp   -= UserControl_MouseLeftButtonUp;
        }

        #endregion

        #region 테두리 사각형 리프레쉬하기 - RefreshBoundRectangle()

        /// <summary>
        /// 테두리 사각형 리프레쉬하기
        /// </summary>
        private void RefreshBoundRectangle()
        {
            if(this.blurRectangle == null || BlurContainer == null || Brush == null)
            {
                return;
            }

            this.differencePoint = this.blurRectangle.TranslatePoint(new Point(), BlurContainer);

            this.scaleX = 1 + 2 * BlurRadius * Magnification / RenderSize.Width;
            this.scaleY = 1 + 2 * BlurRadius * Magnification / RenderSize.Height;

            Size renderSize = new Size(RenderSize.Width * this.scaleX, RenderSize.Height * this.scaleY);

            Brush.Viewbox = new Rect(this.differencePoint, renderSize);

            this.containerSize = BlurContainer.RenderSize;
        }

        #endregion
        #region 효과 리프레쉬하기 - RefreshEffect()

        /// <summary>
        /// 효과 리프레쉬하기
        /// </summary>
        private void RefreshEffect()
        {
            if(this.blurRectangle == null)
            {
                return;
            }

            this.blurRectangle.Effect = new BlurEffect
            {
                Radius        = BlurRadius,
                KernelType    = KernelType.Gaussian,
                RenderingBias = RenderingBias
            };

            this.blurRectangle.RenderTransform = new MatrixTransform
            (
                this.scaleX,
                0,
                0,
                this.scaleY,
                -BlurRadius * Magnification,
                -BlurRadius * Magnification
            );
        }

        #endregion
        #region 비주얼 업데이트하기 - UpdateVisual(oldBlurContainer)

        /// <summary>
        /// 비주얼 업데이트하기
        /// </summary>
        /// <param name="oldBlurContainer">이전 BLUR 컨테이너</param>
        private void UpdateVisual(UIElement oldBlurContainer = null)
        {
            if(oldBlurContainer != null)
            {
                oldBlurContainer.LayoutUpdated -= blurContainer_LayoutUpdated;
            }

            if(BlurContainer != null && this.blurRectangle != null)
            {
                Brush = new VisualBrush(BlurContainer)
                {
                    ViewboxUnits = BrushMappingMode.Absolute,
                    Stretch      = Stretch.None
                };

                BlurContainer.LayoutUpdated += blurContainer_LayoutUpdated;

                RefreshBoundRectangle();

                RefreshEffect();
            }
            else
            {
                Brush = null;
            }
        }

        #endregion
    }
}

 

▶ 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"
    xmlns:local="clr-namespace:TestProject"
    Width="800"
    Height="600"
    Title="반투명 패널 사용하기"
    FontFamily="나눔고딕코딩"
    FontSize="16">
    <Grid>
        <Grid Name="innerGrid">
            <Grid.Background>
                <ImageBrush ImageSource="/IMAGE/sample.png" />
            </Grid.Background>
        </Grid>
        <local:GlassControl
            Panel.ZIndex="100"
            Width="250"
            Height="250"
            BorderBrush="White"
            BorderThickness="3"
            Background="Transparent"
            DragMoveEnabled="True"
            BlurContainer="{Binding ElementName=innerGrid}"
            BlurRadius="45"
            Magnification="0.25">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="*"    />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <TextBlock Grid.Row="0"
                    Margin="5"
                    HorizontalAlignment="Left"
                    VerticalAlignment="Top"
                    TextWrapping="Wrap"
                    Foreground="White"
                    Text="반투명 패널을 드래그할 수 있습니다." />
                <StackPanel Grid.Row="1"
                    HorizontalAlignment="Stretch"
                    VerticalAlignment="Bottom"
                    Orientation="Vertical">
                    <TextBlock
                        Margin="5 0"
                        Foreground="White"
                        Text="확대 :" />
                    <Slider
                        Margin="5"
                        TickPlacement="BottomRight"
                        TickFrequency="0.1"
                        Minimum="0"
                        Maximum="2"
                        Value="{Binding Magnification, RelativeSource={RelativeSource AncestorType={x:Type local:GlassControl}}}" />
                </StackPanel>
                <StackPanel Grid.Row="2"
                    HorizontalAlignment="Stretch"
                    VerticalAlignment="Bottom"
                    Margin="0 5 0 0"
                    Orientation="Vertical">
                    <TextBlock
                        Margin="5 0"
                        Foreground="White"
                        Text="반투명 반경 :" />
                    <Slider
                        Margin="5"
                        TickPlacement="BottomRight"
                        TickFrequency="5"
                        IsSnapToTickEnabled="True"
                        Minimum="0"
                        Maximum="50"
                        Value="{Binding BlurRadius, Mode=TwoWay, RelativeSource={RelativeSource AncestorType={x:Type local:GlassControl}}}" />
                </StackPanel>
            </Grid>
        </local:GlassControl>
    </Grid>
</Window>
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요