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

TestProject.zip
다운로드

▶ MainWindow.cs

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Media;
using System.Windows.Media.Imaging;

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

        #region 생성자 - MainWindow()

        /// <summary>
        /// 생성자
        /// </summary>
        public MainWindow()
        {
            Width      = 800;
            Height     = 600;
            Title      = "RenderTargetBitmap 클래스 : UniformGrid 객체 그리기";
            FontFamily = new FontFamily("나눔고딕코딩");
            FontSize   = 16;

            UniformGrid uniformGrid = new UniformGrid();

            uniformGrid.Columns = 4;

            for(int i = 0; i < 32; i++)
            {
                ToggleButton toggleButton = new ToggleButton();

                toggleButton.Width     = 96d;
                toggleButton.Height    = 24d;
                toggleButton.IsChecked = (i < 4 | i > 27) ^ (i % 4 == 0 | i % 4 == 3);

                uniformGrid.Children.Add(toggleButton);
            }

            uniformGrid.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity));

            Size uniformGridSize = uniformGrid.DesiredSize;

            uniformGrid.Arrange(new Rect(new Point(0, 0), uniformGridSize));

            RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap
            (
                (int)Math.Ceiling(uniformGridSize.Width),
                (int)Math.Ceiling(uniformGridSize.Height),
                96,
                96,
                PixelFormats.Default
            );

            renderTargetBitmap.Render(uniformGrid);

            Image image = new Image();

            image.Source = renderTargetBitmap;
            image.Stretch = Stretch.None;

            Content = image;
        }

        #endregion

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method
        ////////////////////////////////////////////////////////////////////////////////////////// Static
        //////////////////////////////////////////////////////////////////////////////// Public

        #region 프로그램 시작하기 - Main()

        /// <summary>
        /// 프로그램 시작하기
        /// </summary>
        [STAThread]
        public static void Main()
        {
            Application application = new Application();

            application.Run(new MainWindow());
        }

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

댓글을 달아 주세요