첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.
유용한 소스 코드가 있으면 icodebroker@naver.com으로 보내주시면 감사합니다.
블로그 자료는 자유롭게 사용하세요.

728x90
반응형

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="DataGridTemplateColumn 엘리먼트 : CellTemplate/CellEditingTemplate 속성 사용하기"
    FontFamily="나눔고딕코딩"
    FontSize="16">
    <Grid Margin="10">
        <Grid.Resources>
            <DataTemplate x:Key="CellDateTemplateKey" >
                <StackPanel
                    Margin="5"
                    Width="45">
                    <Border
                        BorderBrush="Black"
                        BorderThickness="1"
                        Background="LightBlue">
                        <TextBlock
                            Text="{Binding PublishDate, StringFormat={}{0:MMM}}"
                            HorizontalAlignment="Center" />
                    </Border>
                    <Border
                        BorderBrush="Black"
                        BorderThickness="1"
                        Background="White">
                        <TextBlock
                            HorizontalAlignment="Center"
                            FontWeight="Bold"
                            Text="{Binding PublishDate, StringFormat={}{0:yyyy}}" />
                    </Border>
                </StackPanel>
            </DataTemplate>
            <DataTemplate x:Key="CellEditingDateTemplateKey">
                <DatePicker
                    Margin="5"
                    SelectedDate="{Binding PublishDate}" />
            </DataTemplate>
        </Grid.Resources>
        <DataGrid Name="dataGrid"
            AutoGenerateColumns="False"
            ItemsSource="{Binding}">
            <DataGrid.Columns>
                <DataGridTemplateColumn
                    Header="발행일"
                    CellTemplate="{StaticResource CellDateTemplateKey}"
                    CellEditingTemplate="{StaticResource CellEditingDateTemplateKey}" />
            </DataGrid.Columns>
        </DataGrid>
    </Grid>
</Window>

 

▶ MainWindow.xaml.cs

using System;
using System.Collections.ObjectModel;
using System.Windows;

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

        #region 생성자 - MainWindow()

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

            ObservableCollection<DateInformation> collection = new ObservableCollection<DateInformation>();

            collection.Add(new DateInformation(new DateTime(1999, 3, 23)));
            collection.Add(new DateInformation(new DateTime(1945, 7, 14)));
            collection.Add(new DateInformation(new DateTime(2005, 9, 2 )));
            collection.Add(new DateInformation(new DateTime(1899, 1, 8 )));
            collection.Add(new DateInformation(new DateTime(1983, 6, 20)));

            this.dataGrid.DataContext = collection;
        }

        #endregion
    }
}
728x90
반응형
Posted by 사용자 icodebroker
TAG , ,

댓글을 달아 주세요