첨부 실행 코드는 나눔고딕코딩 폰트를 사용합니다.

728x90
반응형
728x170

TestProject.zip
다운로드

▶ League.cs

using System.Collections.Generic;

namespace TestProject
{
    /// <summary>
    /// 리그
    /// </summary>
    public class League
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Field
        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region Field

        /// <summary>
        /// 명칭
        /// </summary>
        private string name;

        /// <summary>
        /// 디비전 리스트
        /// </summary>
        private List<Division> divisionList;

        #endregion

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

        #region 명칭 - Name

        /// <summary>
        /// 명칭
        /// </summary>
        public string Name
        {
            get
            {
                return this.name;
            }
        }

        #endregion
        #region 디비전 리스트 - DivisionList

        /// <summary>
        /// 디비전 리스트
        /// </summary>
        public List<Division> DivisionList
        {
            get
            {
                return this.divisionList;
            }
        }

        #endregion

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

        #region 생성자 - League(name)

        /// <summary>
        /// 생성자
        /// </summary>
        /// <param name="name">명칭</param>
        public League(string name)
        {
            this.name         = name;
            this.divisionList = new List<Division>();
        }

        #endregion
    }
}

 

728x90

 

▶ Division.cs

using System.Collections.Generic;

namespace TestProject
{
    /// <summary>
    /// 디비전
    /// </summary>
    public class Division
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Field
        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region Field

        /// <summary>
        /// 명칭
        /// </summary>
        private string name;

        /// <summary>
        /// 팀 리스트
        /// </summary>
        private List<Team> teamList;

        #endregion

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

        #region 명칭 - Name

        /// <summary>
        /// 명칭
        /// </summary>
        public string Name
        {
            get
            {
                return this.name;
            }
        }

        #endregion
        #region 팀 리스트 - TeamList

        /// <summary>
        /// 팀 리스트
        /// </summary>
        public List<Team> TeamList
        {
            get
            {
                return this.teamList;
            }
        }

        #endregion

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

        #region 생성자 - Division(name)

        /// <summary>
        /// 생성자
        /// </summary>
        /// <param name="name">명칭</param>
        public Division(string name)
        {
            this.name     = name;
            this.teamList = new List<Team>();
        }

        #endregion
    }
}

 

300x250

 

▶ Team.cs

namespace TestProject
{
    /// <summary>
    /// 팀
    /// </summary>
    public class Team
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Field
        ////////////////////////////////////////////////////////////////////////////////////////// Private

        #region Field

        /// <summary>
        /// 명칭
        /// </summary>
        private string name;

        #endregion

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

        #region 명칭 - Name

        /// <summary>
        /// 명칭
        /// </summary>
        public string Name
        {
            get
            {
                return this.name;
            }
        }

        #endregion

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

        #region 생성자 - Team(name)

        /// <summary>
        /// 생성자
        /// </summary>
        /// <param name="name">명칭</param>
        public Team(string name)
        {
            this.name = name;
        }

        #endregion
    }
}

 

▶ LeagueList.cs

using System.Collections.Generic;

namespace TestProject
{
    /// <summary>
    /// 리그 리스트
    /// </summary>
    public class LeagueList : List<League>
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Property
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region 인덱서 - this[name]

        /// <summary>
        /// 인덱서
        /// </summary>
        /// <param name="name">명칭</param>
        /// <returns>리그</returns>
        public League this[string name]
        {
            get
            {
                foreach(League league in this)
                {
                    if(league.Name == name)
                    {
                        return league;
                    }
                }

                return null;
            }
        }

        #endregion

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

        #region 생성자 - LeagueList()

        /// <summary>
        /// 생성자
        /// </summary>
        public LeagueList()
        {
            League   leauge;
            Division division;

            Add(leauge = new League("League A"));

            leauge.DivisionList.Add((division = new Division("Division A")));

            division.TeamList.Add(new Team("Team I"  ));
            division.TeamList.Add(new Team("Team II" ));
            division.TeamList.Add(new Team("Team III"));
            division.TeamList.Add(new Team("Team IV" ));
            division.TeamList.Add(new Team("Team V"  ));

            leauge.DivisionList.Add((division = new Division("Division B")));

            division.TeamList.Add(new Team("Team Blue"  ));
            division.TeamList.Add(new Team("Team Red"   ));
            division.TeamList.Add(new Team("Team Yellow"));
            division.TeamList.Add(new Team("Team Green" ));
            division.TeamList.Add(new Team("Team Orange"));

            leauge.DivisionList.Add((division = new Division("Division C")));

            division.TeamList.Add(new Team("Team East" ));
            division.TeamList.Add(new Team("Team West" ));
            division.TeamList.Add(new Team("Team North"));
            division.TeamList.Add(new Team("Team South"));

            Add(leauge = new League("League B"));

            leauge.DivisionList.Add((division = new Division("Division A")));

            division.TeamList.Add(new Team("Team 1"));
            division.TeamList.Add(new Team("Team 2"));
            division.TeamList.Add(new Team("Team 3"));
            division.TeamList.Add(new Team("Team 4"));
            division.TeamList.Add(new Team("Team 5"));

            leauge.DivisionList.Add((division = new Division("Division B")));

            division.TeamList.Add(new Team("Team Diamond"));
            division.TeamList.Add(new Team("Team Heart"  ));
            division.TeamList.Add(new Team("Team Club"   ));
            division.TeamList.Add(new Team("Team Spade"  ));

            leauge.DivisionList.Add((division = new Division("Division C")));

            division.TeamList.Add(new Team("Team Alpha"  ));
            division.TeamList.Add(new Team("Team Beta"   ));
            division.TeamList.Add(new Team("Team Gamma"  ));
            division.TeamList.Add(new Team("Team Delta"  ));
            division.TeamList.Add(new Team("Team Epsilon"));
        }

        #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:src="clr-namespace:TestProject"
    Width="800"
    Height="600"
    Title="HierarchicalDataTemplate 엘리먼트 사용하기"
    FontFamily="나눔고딕코딩"
    FontSize="16">
    <Window.Resources>
        <Style TargetType="{x:Type TreeViewItem}">
            <Setter Property="Padding" Value="5" />
        </Style>
    </Window.Resources>
    <DockPanel>
        <DockPanel.Resources>
            <src:LeagueList x:Key="LeagueListKey" />
            <HierarchicalDataTemplate DataType="{x:Type src:League}"
                ItemsSource="{Binding Path=DivisionList}">
                <TextBlock Text="{Binding Path=Name}" />
            </HierarchicalDataTemplate>
            <HierarchicalDataTemplate DataType="{x:Type src:Division}"
                ItemsSource="{Binding Path=TeamList}">
                <TextBlock Text="{Binding Path=Name}" />
            </HierarchicalDataTemplate>
            <DataTemplate DataType="{x:Type src:Team}">
                <TextBlock Text="{Binding Path=Name}" />
            </DataTemplate>
        </DockPanel.Resources>
        <Menu Name="menu" DockPanel.Dock="Top"
            Padding="5"
            FontFamily="나눔고딕코딩"
            FontSize="16">
            <MenuItem Header="축구 리그"
                ItemsSource="{Binding Source={StaticResource LeagueListKey}}" />
        </Menu>
        <TreeView
            Margin="10"
            Padding="10">
            <TreeViewItem
                Header="축구 리그"
                ItemsSource="{Binding Source={StaticResource LeagueListKey}}" />
        </TreeView>
    </DockPanel>
</Window>
728x90
반응형
그리드형(광고전용)
Posted by icodebroker

댓글을 달아 주세요