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

TestProject.zip
0.01MB

▶ StudentModel.cs

using System.Collections.Generic;

namespace TestProject
{
    /// <summary>
    /// 학생 모델
    /// </summary>
    public class StudentModel
    {
        //////////////////////////////////////////////////////////////////////////////////////////////////// Property
        ////////////////////////////////////////////////////////////////////////////////////////// Public

        #region ID - ID

        /// <summary>
        /// ID
        /// </summary>
        public int ID { get; set; }

        #endregion
        #region 성명 - NAME

        /// <summary>
        /// 성명
        /// </summary>
        public string NAME { get; set; }

        #endregion

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

        #region 학생 리스트 구하기 - GetStudentList(count)

        /// <summary>
        /// 학생 리스트 구하기
        /// </summary>
        /// <param name="count">ㅅ학생 수</param>
        /// <returns>학생 리스트</returns>
        public static List<StudentModel> GetStudentList(int count)
        {
            List<StudentModel> list = new List<StudentModel>();

            for(int i = 0; i < count; i++)
            {
                list.Add(new StudentModel { ID = i, NAME = $"학생{i}" });
            }

            return list;
        }

        #endregion
    }
}

 

728x90

 

▶ 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="ListBox 엘리먼트 : IsSynchronizedWithCurrentItem 속성을 사용해 현재 항목 동기화 설정하기"
    FontFamily="나눔고딕코딩"
    FontSize="16">
    <Grid Margin="10">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"  />
            <ColumnDefinition Width="10" />
            <ColumnDefinition Width="*"  />
        </Grid.ColumnDefinitions>
        <ListBox Name="listBox1" Grid.Column="0"
            IsSynchronizedWithCurrentItem="True"
            DisplayMemberPath="NAME" />
        <ListBox Name="listBox2" Grid.Column="2"
            IsSynchronizedWithCurrentItem="True"
            DisplayMemberPath="NAME" />
    </Grid>
</Window>

 

300x250

 

▶ MainWindow.xaml.cs

using System.Collections.Generic;
using System.Windows;

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

        #region 생성자 - MainWindow()

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

            List<StudentModel> list = StudentModel.GetStudentList(10000);

            this.listBox1.ItemsSource = list;
            this.listBox2.ItemsSource = list;
        }

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

댓글을 달아 주세요