[C#/WPF] ListBox 엘리먼트 : IsSynchronizedWithCurrentItem 속성을 사용해 현재 항목 동기화 설정하기
C#/WPF 2022. 5. 28. 18:31728x90
반응형
728x170
▶ 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
반응형
그리드형(광고전용)
'C# > WPF' 카테고리의 다른 글
[C#/WPF] BlurEffect 엘리먼트 : 네온싸인 효과 만들기 (0) | 2022.07.23 |
---|---|
[C#/WPF] DropShadowEffect 엘리먼트 : 네온싸인 효과 만들기 (0) | 2022.07.23 |
[C#/WPF] DropShadowEffect 엘리먼트 : 네온싸인 효과 만들기 (0) | 2022.07.23 |
[C#/WPF] ControlTemplate 엘리먼트 : ToggleButton 엘리먼트를 정의해 전원 버튼 만들기 (0) | 2022.07.23 |
[C#/WPF] ControlTemplate 엘리먼트 : ToggleButton 엘리먼트를 정의해 재생 버튼 만들기 (0) | 2022.07.23 |
[C#/WPF] DateTemplate 클래스 : FindName 메소드를 사용해 자식 객체 구하기 (0) | 2022.05.28 |
[C#/WPF] ControlTemplate 엘리먼트 : Button 엘리먼트 정의하기 (0) | 2022.05.25 |
[C#/WPF] ContentPresenter 엘리먼트 : RecognizesAccessKey 속성을 사용해 액세스 키 사용 여부 설정하기 (0) | 2022.05.25 |
[C#/WPF] ContentControl 클래스 : 원형 파급 효과 애니메이션 컨트롤 만들기 (0) | 2022.05.25 |
[C#/WPF] WebBrowser 엘리먼트 : 스크립트 오류 억제하기 (0) | 2022.05.24 |
댓글을 달아 주세요