로딩
요청 처리 중입니다...

[WPF] DataContext

 [WPF] DataContext

데이터 중심 애플리케이션의 화면에서 시각적으로 그룹화된 대부분의 컨트롤은 동일한 데이터 객체의 데이터를 사용한다. 그러므로 바인딩에 대해 작성한 XAML을 단순화하기 위해 DataContext를 사용한다.

바인딩에서 ElementName, Source 속성을 사용하여 소스 데이터 객체를 지정하지 않으면 소스가 현재 DataContext로 간주된다. DataContext를 이용해 Window의 너비와 높이를 보여주는 예제이다.

MainWindow.xaml.cs public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); this.DataContext = this; } } Window의 DataContext에 this로 인해 MainWindow가 설정된다. MainWindow.xaml

# DataContext # WPF

원문 링크 : [WPF] DataContext