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

TestProject.zip
0.01MB

▶ DelegateCommand.cs

using System;
using System.Windows.Input;

namespace TestProject
{
    /// <summary>
    /// 대리자 명령
    /// </summary>
    public class DelegateCommand : ICommand
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Event
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 실행 가능 여부 변경시 이벤트 - CanExecuteChanged

        /// <summary>
        /// 실행 가능 여부 변경시 이벤트
        /// </summary>
        public event EventHandler CanExecuteChanged
        {
            add
            {
                CommandManager.RequerySuggested += value;
            }
            remove
            {
                CommandManager.RequerySuggested -= value;
            }
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Field
        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region Field

        /// <summary>
        /// 실행 액션
        /// </summary>
        private readonly Action<object> executeAction;

        /// <summary>
        /// 실행 가능 여부 함수
        /// </summary>
        private readonly Func<object, bool> canExecuteFunction;

        #endregion

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

        #region 생성자 - DelegateCommand(executeAction, canExecuteFunction)

        /// <summary>
        /// 생성자
        /// </summary>
        /// <param name="executeAction">실행 액션</param>
        /// <param name="canExecuteFunction">실행 가능 여부 함수</param>
        public DelegateCommand(Action<object> executeAction, Func<object, bool> canExecuteFunction)
        {
            if(executeAction is null)
            {
                throw new ArgumentNullException(nameof(executeAction));
            }

            this.executeAction      = executeAction;
            this.canExecuteFunction = canExecuteFunction ?? (x => true);
        }

        #endregion
        #region 생성자 - DelegateCommand(executeAction)

        /// <summary>
        /// 생성자
        /// </summary>
        /// <param name="executeAction">실행 액션</param>
        public DelegateCommand(Action<object> executeAction) : this(executeAction, null)
        {
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 실행 가능 여부 구하기 - CanExecute(parameter)

        /// <summary>
        /// 실행 가능 여부 구하기
        /// </summary>
        /// <param name="parameter">매개 변수</param>
        /// <returns>실행 가능 여부</returns>
        public bool CanExecute(object parameter) => this.canExecuteFunction(parameter);

        #endregion
        #region 실행하기 - Execute(parameter)

        /// <summary>
        /// 실행하기
        /// </summary>
        /// <param name="parameter">매개 변수</param>
        public void Execute(object parameter) => this.executeAction(parameter);

        #endregion
        #region 갱신하기 - Refresh()

        /// <summary>
        /// 갱신하기
        /// </summary>
        public void Refresh() => CommandManager.InvalidateRequerySuggested();

        #endregion
    }
}

 

728x90

 

▶ MainApplicaton.xaml

<Application x:Class="TestProject.MainApplication"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
    StartupUri="MainWindow.xaml">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <materialDesign:BundledTheme BaseTheme="Inherit" PrimaryColor="DeepPurple" SecondaryColor="Lime" ColorAdjustment="{materialDesign:ColorAdjustment}" />
                <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>

 

반응형

 

▶ 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:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
    Width="800"
    Height="600"
    Title="Button 클래스 : 머터리얼 디자인(Material Design) 사용하기"
    Background="{DynamicResource MaterialDesignPaper}"
    FontFamily="나눔고딕코딩"
    FontSize="16">
    <Grid>
        <Grid
            HorizontalAlignment="Center"
            VerticalAlignment="Center">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            <StackPanel Grid.Row="0"
                HorizontalAlignment="Center"
                Orientation="Horizontal">
                <Button Style="{StaticResource MaterialDesignFloatingActionMiniLightButton}"
                    Margin="10">
                    <materialDesign:PackIcon
                        Width="24"
                        Height="24"
                        Kind="Alarm" />
                </Button>
                <Button Style="{StaticResource MaterialDesignFloatingActionMiniButton}"
                    Margin="10">
                    <materialDesign:PackIcon
                        Width="24"
                        Height="24"
                        Kind="Alarm" />
                </Button>
                <Button Style="{StaticResource MaterialDesignFloatingActionMiniDarkButton}"
                    Margin="10">
                    <materialDesign:PackIcon
                        Width="24"
                        Height="24"
                        Kind="Alarm" />
                </Button>

                <Button Style="{StaticResource MaterialDesignFloatingActionMiniSecondaryLightButton}"
                    Margin="10">
                    <materialDesign:PackIcon
                        Width="24"
                        Height="24"
                        Kind="Alarm" />
                </Button>
                <Button Style="{StaticResource MaterialDesignFloatingActionMiniSecondaryButton}"
                    Margin="10">
                    <materialDesign:PackIcon
                        Width="24"
                        Height="24"
                        Kind="Alarm" />
                </Button>
                <Button Style="{StaticResource MaterialDesignFloatingActionMiniSecondaryDarkButton}"
                    Margin="10">
                    <materialDesign:PackIcon
                        Width="24"
                        Height="24"
                        Kind="Alarm" />
                </Button>
            </StackPanel>
            <StackPanel Grid.Row="1"
                HorizontalAlignment="Center"
                Orientation="Horizontal">
                <Button Style="{StaticResource MaterialDesignFloatingActionLightButton}"
                    Margin="10">
                    <materialDesign:PackIcon
                        Width="24"
                        Height="24"
                        Kind="Alarm" />
                </Button>
                <Button Style="{StaticResource MaterialDesignFloatingActionButton}"
                    Margin="10">
                    <materialDesign:PackIcon
                        Width="24"
                        Height="24"
                        Kind="Alarm" />
                </Button>
                <Button Style="{StaticResource MaterialDesignFloatingActionDarkButton}"
                    Margin="10">
                    <materialDesign:PackIcon
                        Width="24"
                        Height="24"
                        Kind="Alarm" />
                </Button>

                <Button Style="{StaticResource MaterialDesignFloatingActionSecondaryLightButton}"
                    Margin="10">
                    <materialDesign:PackIcon
                        Width="24"
                        Height="24"
                        Kind="Alarm" />
                </Button>
                <Button Style="{StaticResource MaterialDesignFloatingActionSecondaryButton}"
                    Margin="10">
                    <materialDesign:PackIcon
                        Width="24"
                        Height="24"
                        Kind="Alarm" />
                </Button>
                <Button Style="{StaticResource MaterialDesignFloatingActionSecondaryDarkButton}"
                    Margin="10">
                    <materialDesign:PackIcon
                        Width="24"
                        Height="24"
                        Kind="Alarm" />
                </Button>
            </StackPanel>
            <StackPanel Grid.Row="2"
                HorizontalAlignment="Center"
                Orientation="Horizontal">
                <Button Style="{StaticResource MaterialDesignRaisedLightButton}"
                    Margin="10"
                    Width="90"
                    Content="_LIGHT" />
                <Button Style="{StaticResource MaterialDesignRaisedButton}"
                    Margin="10"
                    Width="90"
                    Content="_MID" />
                <Button Style="{StaticResource MaterialDesignRaisedDarkButton}"
                    Margin="10"
                    Width="90"
                    Content="_DARK" />

                <Button Style="{StaticResource MaterialDesignRaisedSecondaryLightButton}"
                    Margin="10"
                    Width="90"
                    Content="LIGHT" />
                <Button Style="{StaticResource MaterialDesignRaisedSecondaryButton}"
                    Margin="10"
                    Width="90"
                    Content="MID" />
                <Button Style="{StaticResource MaterialDesignRaisedSecondaryDarkButton}"
                    Margin="10"
                    Width="90"
                    Content="DARK" />
            </StackPanel>
            <StackPanel Grid.Row="3"
                HorizontalAlignment="Center"
                Orientation="Horizontal">
                <Button Style="{StaticResource MaterialDesignPaperLightButton}"
                    Margin="10"
                    Width="90"
                    Content="LIGHT" />
                <Button Style="{StaticResource MaterialDesignPaperButton}"
                    Margin="10"
                    Width="90"
                    Content="MID" />
                <Button Style="{StaticResource MaterialDesignPaperDarkButton}"
                    Margin="10"
                    Width="90"
                    Content="DARK" />

                <Button Style="{StaticResource MaterialDesignPaperSecondaryLightButton}"
                    Margin="10"
                    Width="90"
                    Content="LIGHT" />
                <Button Style="{StaticResource MaterialDesignPaperSecondaryButton}"
                    Margin="10"
                    Width="90"
                    Content="MID" />
                <Button Style="{StaticResource MaterialDesignPaperSecondaryDarkButton}"
                    Margin="10"
                    Width="90"
                    Content="DARK" />
            </StackPanel>
            <StackPanel Grid.Row="4"
                HorizontalAlignment="Center"
                Orientation="Horizontal">
                <Button Style="{StaticResource MaterialDesignFlatLightButton}"
                    Margin="10"
                    Width="90"
                    Content="LIGHT" />
                <Button Style="{StaticResource MaterialDesignFlatButton}"
                    Margin="10"
                    Width="90"
                    Content="MID" />
                <Button Style="{StaticResource MaterialDesignFlatDarkButton}"
                    Margin="10"
                    Width="90"
                    Content="DARK" />

                <Button Style="{StaticResource MaterialDesignFlatSecondaryLightButton}"
                    Margin="10"
                    Width="90"
                    Content="LIGHT" />
                <Button Style="{StaticResource MaterialDesignFlatSecondaryButton}"
                    Margin="10"
                    Width="90"
                    Content="MID" />
                <Button Style="{StaticResource MaterialDesignFlatSecondaryDarkButton}"
                    Margin="10"
                    Width="90"
                    Content="DARK" />
            </StackPanel>
            <StackPanel Grid.Row="5"
                HorizontalAlignment="Center"
                Orientation="Horizontal">
                <Button Style="{StaticResource MaterialDesignOutlinedLightButton}"
                    Margin="10"
                    Width="90"
                    Content="LIGHT" />
                <Button Style="{StaticResource MaterialDesignOutlinedButton}"
                    Margin="10"
                    Width="90"
                    Content="MID" />
                <Button Style="{StaticResource MaterialDesignOutlinedDarkButton}"
                    Margin="10"
                    Width="90"
                    Content="DARK" />

                <Button Style="{StaticResource MaterialDesignOutlinedSecondaryLightButton}"
                    Margin="10"
                    Width="90"
                    Content="LIGHT" />
                <Button Style="{StaticResource MaterialDesignOutlinedSecondaryButton}"
                    Margin="10"
                    Width="90"
                    Content="MID" />
                <Button Style="{StaticResource MaterialDesignOutlinedSecondaryDarkButton}"
                    Margin="10"
                    Width="90"
                    Content="DARK" />
            </StackPanel>
            <StackPanel Grid.Row="6"
                HorizontalAlignment="Center"
                Orientation="Horizontal">
                <Button Style="{StaticResource MaterialDesignFlatLightBgButton}"
                    Margin="10"
                    Width="90"
                    Content="LIGHT" />
                <Button Style="{StaticResource MaterialDesignFlatMidBgButton}"
                    Margin="10"
                    Width="90"
                    Content="MID" />
                <Button Style="{StaticResource MaterialDesignFlatDarkBgButton}"
                    Margin="10"
                    Width="90"
                    Content="DARK" />
                <Button Style="{StaticResource MaterialDesignFlatSecondaryLightBgButton}"
                    Margin="10"
                    Width="90"
                    Content="LIGHT" />
                <Button Style="{StaticResource MaterialDesignFlatSecondaryMidBgButton}"
                    Margin="10"
                    Width="90"
                    Content="MID" />
                <Button Style="{StaticResource MaterialDesignFlatSecondaryDarkBgButton}"
                    Margin="10"
                    Width="90"
                    Content="DARK" />
            </StackPanel>
            <StackPanel Grid.Row="7"
                HorizontalAlignment="Center"
                Orientation="Horizontal">
                <materialDesign:Badged
                    Margin="10"
                    Badge="3">
                    <Button
                        Content="MAIL" />
                </materialDesign:Badged>
                <materialDesign:Badged
                    Margin="10"
                    Badge="{materialDesign:PackIcon Heart}"
                    BadgeColorZoneMode="SecondaryMid">
                    <Button
                        Content="LOVE" />
                </materialDesign:Badged>
                <materialDesign:Badged
                    Margin="10"
                    Badge="DANGER"
                    BadgeColorZoneMode="Dark">
                    <Button
                        Content="STATUS" />
                </materialDesign:Badged>
                <materialDesign:Badged Name="countingBadge"
                    Margin="10"
                    BadgeColorZoneMode="PrimaryDark">
                    <Button Style="{StaticResource MaterialDesignRaisedLightButton}"
                        Content="CLICK ME!"
                        Click="countingButton_Click" />
                </materialDesign:Badged>
                <Button Style="{StaticResource MaterialDesignRaisedLightButton}"
                    Margin="10"
                    Width="150"
                    ContentStringFormat="OR CLICK ME {0}"
                    Content="{Binding ClickCount}"
                    Command="{Binding ClickCommand }" />
                <Button
                    Margin="10"
                    Content="{materialDesign:PackIcon AirplaneTakeoff}" />
            </StackPanel>
            <StackPanel Grid.Row="8"
                HorizontalAlignment="Center"
                Orientation="Horizontal">
                <Button Style="{StaticResource MaterialDesignRaisedAccentButton}"
                    Margin="10"
                    Width="150"
                    materialDesign:RippleAssist.Feedback="#dd000000"
                    Content="CUSTOM RIPPLE" />
                <Button Style="{StaticResource MaterialDesignRaisedAccentButton}"
                    Margin="10"
                    Width="150"
                    materialDesign:RippleAssist.IsDisabled="True"
                    Content="NO RIPPLE" />
                <RepeatButton
                    Width="150"
                    Content="REPEAT" />
            </StackPanel>
            <StackPanel Grid.Row="9"
                HorizontalAlignment="Center"
                Orientation="Horizontal">
                <Button Style="{StaticResource MaterialDesignIconButton}"
                    Margin="10">
                    <materialDesign:PackIcon Kind="Play" />
                </Button>
                <Button Style="{StaticResource MaterialDesignIconForegroundButton}"
                    Margin="10">
                    <materialDesign:PackIcon Kind="Play" />
                </Button>
                <Button Style="{StaticResource MaterialDesignIconButton}"
                    Margin="10"
                    Background="{DynamicResource MaterialDesignTextFieldBoxBackground}">
                    <materialDesign:PackIcon Kind="Play" />
                </Button>
            </StackPanel>
        </Grid>
    </Grid>
</Window>

 

300x250

 

▶ MainWindow.xaml.cs

using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows;
using System.Windows.Input;

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

        #region 속성 변경시 - PropertyChanged

        /// <summary>
        /// 속성 변경시
        /// </summary>
        public event PropertyChangedEventHandler PropertyChanged;

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Field
        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region Field

        /// <summary>
        /// 클릭 카운트
        /// </summary>
        private int clickCount;

        #endregion

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

        #region 클릭 카운트 - ClickCount

        /// <summary>
        /// 클릭 카운트
        /// </summary>
        public int ClickCount
        {
            get => this.clickCount;
            private set => SetProperty(ref this.clickCount, value);
        }

        #endregion
        #region 클릭 명령 - ClickCommand

        /// <summary>
        /// 클릭 명령
        /// </summary>
        public ICommand ClickCommand { get; }

        #endregion

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

        #region 생성자 - MainWindow()

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

            ClickCount   = 0;
            ClickCommand = new DelegateCommand(_ => ClickCount += 1);

            DataContext = this;
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Private
        //////////////////////////////////////////////////////////////////////////////// Event

        #region 카운팅 버튼 클릭시 처리하기 - countingButton_Click(sender, e)

        /// <summary>
        /// 카운팅 버튼 클릭시 처리하기
        /// </summary>
        /// <param name="sender">이벤트 발생자</param>
        /// <param name="e">이벤트 인자</param>
        private void countingButton_Click(object sender, RoutedEventArgs e)
        {
            if(this.countingBadge.Badge == null || Equals(this.countingBadge.Badge, string.Empty))
            {
                this.countingBadge.Badge = 0;
            }

            int nextCount = int.Parse(this.countingBadge.Badge.ToString() ?? "0") + 1;

            this.countingBadge.Badge = nextCount < 21 ? (object)nextCount : null;
        }

        #endregion

        ////////////////////////////////////////////////////////////////////////////////////////// Protected
        //////////////////////////////////////////////////////////////////////////////// Function

        #region 속성 변경시 이벤트 발생시키기 - FirePropertyChangedEvent(propertyName)

        /// <summary>
        /// 속성 변경시 이벤트 발생시키기
        /// </summary>
        /// <param name="propertyName">속성명</param>
        protected void FirePropertyChangedEvent([CallerMemberName] string propertyName = null)
            => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));

        #endregion
        #region 속성 설정하기 - SetProperty<T>(member, value, propertyName)

        /// <summary>
        /// 속성 설정하기
        /// </summary>
        /// <typeparam name="T">타입</typeparam>
        /// <param name="member">멤버</param>
        /// <param name="value">값</param>
        /// <param name="propertyName">속성명</param>
        /// <returns>처리 결과</returns>
        protected virtual bool SetProperty<T>(ref T member, T value, [CallerMemberName] string propertyName = null)
        {
            if(EqualityComparer<T>.Default.Equals(member, value))
            {
                return false;
            }

            member = value;

            FirePropertyChangedEvent(propertyName);

            return true;
        }

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

댓글을 달아 주세요