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

■ TreeView 클래스 사용하기

----------------------------------------------------------------------------------------------------


TestProject.zip


MainWindow.cs

 

 

using System;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Media;

 

namespace TestProject

{

    /// <summary>

    /// 메인 윈도우

    /// </summary>

    public class MainWindow : Window

    {

        //////////////////////////////////////////////////////////////////////////////////////////////////// Constructor

        ////////////////////////////////////////////////////////////////////////////////////////// Public

 

        #region 생성자 - MainWindow()

 

        /// <summary>

        /// 생성자

        /// </summary>

        public MainWindow()

        {

            Width      = 800;

            Height     = 600;

            Title      = "TreeView 클래스 사용하기";

            FontFamily = new FontFamily("나눔고딕코딩");

            FontSize   = 16;

 

            TreeView treeView = new TreeView();

 

            Content = treeView;

 

            #region Aniaml 노드

 

            TreeViewItem animalTreeViewItem = new TreeViewItem();

 

            animalTreeViewItem.Header = "Animal";

 

            treeView.Items.Add(animalTreeViewItem);

 

            #endregion

                #region Dog 노드

 

                TreeViewItem dogTreeViewItem = new TreeViewItem();

 

                dogTreeViewItem.Header = "Dog";

 

                animalTreeViewItem.Items.Add(dogTreeViewItem);

 

                #endregion

 

                    dogTreeViewItem.Items.Add("Poodle"         );

                    dogTreeViewItem.Items.Add("Irish Setter"   );

                    dogTreeViewItem.Items.Add("German Shepherd");

 

                #region Cat 노드

 

                TreeViewItem catTreeViewItem = new TreeViewItem();

 

                catTreeViewItem.Header = "Cat";

 

                animalTreeViewItem.Items.Add(catTreeViewItem);

 

                #endregion

 

                    catTreeViewItem.Items.Add("Calico");

 

                    #region Alley Cat 노드

 

                    TreeViewItem alleyCatTreeViewItem = new TreeViewItem();

 

                    alleyCatTreeViewItem.Header = "Alley Cat";

 

                    catTreeViewItem.Items.Add(alleyCatTreeViewItem);

 

                    #endregion

                    #region Noodles 버튼

 

                    Button noodlesButton = new Button();

 

                    noodlesButton.Content = "Noodles";

 

                    catTreeViewItem.Items.Add(noodlesButton);

 

                    #endregion

 

                    catTreeViewItem.Items.Add("Siamese");

 

                #region Primate 노드

 

                TreeViewItem primateTreeViewItem = new TreeViewItem();

 

                primateTreeViewItem.Header = "Primate";

 

                animalTreeViewItem.Items.Add(primateTreeViewItem);

 

                #endregion

 

                    primateTreeViewItem.Items.Add("Chimpanzee");

                    primateTreeViewItem.Items.Add("Bonobo"    );

                    primateTreeViewItem.Items.Add("Human"     );

 

            #region Mineral 노드

 

            TreeViewItem mineralTreeViewItem = new TreeViewItem();

 

            mineralTreeViewItem.Header = "Mineral";

 

            treeView.Items.Add(mineralTreeViewItem);

 

            #endregion

 

                mineralTreeViewItem.Items.Add("Calcium");

                mineralTreeViewItem.Items.Add("Zinc"   );

                mineralTreeViewItem.Items.Add("Iron"   );

 

            #region Vegetable 노드

 

            TreeViewItem vegetableTreeViewItem = new TreeViewItem();

 

            vegetableTreeViewItem.Header = "Vegetable";

 

            treeView.Items.Add(vegetableTreeViewItem);

 

            #endregion

 

                vegetableTreeViewItem.Items.Add("Carror"   );

                vegetableTreeViewItem.Items.Add("Asparagus");

                vegetableTreeViewItem.Items.Add("Broccoli" );

        }

 

        #endregion

 

        //////////////////////////////////////////////////////////////////////////////////////////////////// Method

        ////////////////////////////////////////////////////////////////////////////////////////// Static

        //////////////////////////////////////////////////////////////////////////////// Public

 

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

 

        /// <summary>

        /// 프로그램 시작하기

        /// </summary>

        [STAThread]

        public static void Main()

        {

            Application application = new Application();

 

            application.Run(new MainWindow());

        }

 

        #endregion

    }

}

 

----------------------------------------------------------------------------------------------------

Posted by 사용자 icodebroker
TAG

댓글을 달아 주세요