TemplateBinding vs TemplatedParent

3155 단어 wpfwpf

TemplateBinding, TemplatedParent

두 기법 모두 Template이 적용된 Element의 속성과 바인딩 하기 위해 존재한다.

TemplateBinding

EX) TemplateBinding

<ControlTemplate TargetType="{x:Type Button}">
   <Border BorderBrush="{TemplateBinding Property=Background}">
      <ContentPresenter />
   </Border>
</ControlTemplate>
  • TemplateBindings는 ControlTemplate에 지정된 타입에 대해 컴파일 타임에 처리된다.
    이를 통해 Template 컴파일이 빠르다.
  • ControlTemplate 안에서만 사용 가능하다.
  • Value Converting 사용할 수 없다.

TemplatedParent

EX) TemplatedParent

<ControlTemplate TargetType="{x:Type Button}">
   <Border BorderBrush="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Background}">
      <ContentPresenter />
   </Border>
</ControlTemplate>
  • 일반적인 바인딩 방식이다
  • 런타임에 처리된다. 그래서 컴파일이 더 느리다.

좋은 웹페이지 즐겨찾기