사용자 도구

사이트 도구


사이드바

카테고리

sdk:wpf:데이터-바인딩

쉬운 듯10% 복잡한듯90%

xaml 헤더

는 거의 같다.

<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
 
        mc:Ignorable="d"
 
        x:Class="네임스페이스.해당 윈도우 클래스"
        xmlns:local="clr-namespace:네임스페이스"
        Title="MainWindow" Height="400" Width="525" MinWidth="525" MinHeight="400"
        WindowStartupLocation='CenterScreen'
        >
x:Class="..." : 현재 앱의 네임스페이스와 윈도우 클래스 이름
xmlns:local="clr-namespace:네임스페이스" : local 은 임의로 정한 이름. 바꿔 써도 된다.

데이터를 바인딩 할때 연결할 것들

DataContext : 코드 또는 xaml에서 연결할 데이터(프로퍼티들)가 어디 있는지 명시 해야 한다.
// MainWindow.xaml.cs 파일이고 MainWindow.xaml과 연결되는 거라면
public class MainWindow {
  public MainWindow() {
    this.DataContext = this;
  }
}

DataContext를 MainWindow로 설정 했으므로, MainWindow의 프로퍼티는 Path키워드로 설정 가능하다.

<TextBox x:Name="TargetFolderPath" Text="{Binding Path=SelectedPath}" />
<!--
    x:Name 은 이 컨트롤의 이름을 설정하는 것. 코드에서 TargetFolderPath 를 쓸 수 있다.
    SelectedPath 는 MainWindow의 프로퍼티. 
-->

Path 와 XPath

  • Path 로 쓸 수 있는 것은 오브젝트의 프로퍼티.
  • XPath 로 쓸 수 있는 것은 xml 의 엘리먼트 요소.

외부 참조

sdk/wpf/데이터-바인딩.txt · 마지막으로 수정됨: 2017/07/11 18:45 저자 kieuns