'Functional World/WPF' 카테고리의 글 목록 :: iopeni - Think of C#

이전 포스팅에서 하드 코딩 된 맵핑 정보에 대한 글을 쓴 적이 있습니다.


마이크로소프트도 했는데... 나라고 못 할쏘냐~~~~ 


나의 어플리케이션에서도 나만의 네임스페이스를 맵핑 하고 싶을 수 있습니다.


이때 사용 할 수 있는 방법을 정리 합니다.


프로젝트의 Properties 항목의 AssembleyInfo.cs 파일을 Open 해서...


제일 하단에 이렇게 추가 합니다.


이제 코드에서 사용 할 수 있습니다.


xmlns:mc="http://iopeni.com/compressor"


으로 말이죠...!!!!!!!!!

Posted by 프로그래머란 카페인을 코드로 변환하는 기계다
,

살면서 언제나 처음 보는 용어를 이해하는데는 상당한 시간과 노력이 필요 한듯 합니다.


WPF는 선언형 기반의 프로그래밍 언어 입니다.


XAML이라는 선언형 프로그래밍 언어로 Object를 선언하고 컴파일러는 이 언어를 파싱하여 가지고 각각의 Object를 생성합니다.


XAML 코드를 하나 보도록 하죠.

<window x:class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" title="MainWindow" height="350" width="525">
    <grid>
        <button>
            OK
        </button>
    </grid>
</window>

위 XML코드를 보면 Window 와 Grid, Button이라는 2개의 컨트롤과 1개의 윈도우를 생성하고 있습니다. 


Winform 형태의 프로그래밍을 보면 Grid와 Button은 동일 선상에 놓여 있는 Object 입니다. 그리드 안에 표현하기 위하여 우리는 그리드의 Contorls 컬렉션에 Add 하는 것으로 종속 관계를 표현 할 수 있겠죠.


그런데 WPF는 아닙니다. 어떻게 보면 컨트롤 자체가 컬렉션 처럼 보이기도 합니다. 그냥 <Grid>라는 태그를 선언하고 </Grid> 안에 <Button/>을 등록하는 것으로 Grid에 포함된 버튼이 생성 됩니다. 이런 형태로 종속관계의 Tree가 그려지게 됩니다. WPF에서는 이런 관계가 논리적트리(LogicalTree), 비주얼트리(VisualTree)라는 것으로 생성 됩니다. 


WPF는 화면을 디자인 할 때 기본으로 종속관계가 도식화 되며 이로 인하여, 각각의 컨트롤간 의존성을 띄게 되기 때문에 의존객체(DependencyObject)라고 표현 되게 되는 것입니다. 


이렇게 의존성을 띄게 되는 컨트롤만이 있다면 이건 뭔가 좀 이상해 보일 수도 있습니다.


의존프로퍼티가 이런 의존객체를 토대로 만들어진 개념입니다. 각 객체가 기본 의존성을 띄게 된다면 각 부모 객체의 프로퍼티에 의존성을 두기 쉽게 된 이유 입니다. 


즉 하나의 객체가 다른 객체에 포함된 경우라면 상위 객체의 프로퍼티 값을 상속 받아 기본 값으로 셋팅 되도록 구성 되었다는 것입니다.


<window x:class="WpfApplication1.MainWindow" 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
title="MainWindow" height="350" width="525" fontsize="44">
    <grid>
        <button>
            OK
        </button>
        <button>
           OK
        </button>
    </grid>
</window>

와 같이 윈도우 객체의 FontSize를 44와 같이 두게 된다면 그 안에 있는 그리드와 버튼의 폰트 사이즈가 44로 셋팅 되는 의존성을 갖게 된다는 것입니다.


이 의존성에는 커다란 규칙이 하나 존재 하는데


프로퍼티 값 기준 결정 이라는 것입니다.

  • 로컬 값 설정(Local Value)
  • 스타일 트리거(Style Triggers)
  • 템플릿 트리거(Template Triggers)
  • 스타일 세터(Style Setters)
  • 테마 스타일 트리거(Theme Style Triggers)
  • 테마 스타일 세터(Theme Style Setters)
  • 프로퍼티 값 상속(Property Value Inheritance)
  • 기본 값(Default Value)

등의 순서로 의존성을 띄게 됩니다.


일단 의존객체라는 것과 의존프로퍼티의 의미를 알았다는 것으로 이 포스트를 마무리 할까 합니다.


애덤 네이선은 이렇게 이야기 하고 있습니다.


"WPF가 선언형 프로그래밍 언어 일 수 있는 것은 바로 의존객체와 의존프로퍼티 때문에 가능한 일이다." 라고 말입니다.



Posted by 프로그래머란 카페인을 코드로 변환하는 기계다
,

WPF를 처음 접하였을 때 정말 복잡한 암호 처럼 보였던 

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

라는 문장을 보며 당췌 이게 뭐하는 것인지 몰랐습니다.


익스플로러에 저 URL을 두들겨 봐도 아무것도 없는 황당함... 외우는 것에 취약한 저는 쉐뜨를 연발 하며, WPF는 내가 공부 할 수 있는 뭔가가 아닌가보다 라며 절망에 빠졌던 기억이 있습니다.


어셈블리 PresentationFramework.dll version 4.0.0.0 을 디스어셈블 하여 보니....

다음과 같이 NameSpace와 맵핑 된 것이 하드 코딩 되어 있는 것을 확인 할 수 있었습니다.


1. winfx 영역

XmlnsDefinition("http://schemas.microsoft.com/winfx/2006/xaml/presentation", "System.Windows.Shapes")

XmlnsDefinition("http://schemas.microsoft.com/winfx/2006/xaml/presentation", "System.Windows.Navigation")

XmlnsDefinition("http://schemas.microsoft.com/winfx/2006/xaml/presentation", "System.Windows.Controls")

XmlnsDefinition("http://schemas.microsoft.com/winfx/2006/xaml/presentation", "System.Windows.Documents")

XmlnsDefinition("http://schemas.microsoft.com/winfx/2006/xaml/presentation", "System.Windows.Shell")

XmlnsDefinition("http://schemas.microsoft.com/winfx/2006/xaml/presentation", "System.Windows.Data")

XmlnsDefinition("http://schemas.microsoft.com/winfx/2006/xaml/presentation", "System.Windows")

XmlnsDefinition("http://schemas.microsoft.com/winfx/2006/xaml/presentation","System.Windows.Controls.Primitives")

XmlnsDefinition("http://schemas.microsoft.com/winfx/2006/xaml/presentation","System.Windows.Media.Animation")

XmlnsDefinition("http://schemas.microsoft.com/winfx/2006/xaml/presentation", "System.Windows.Input")

XmlnsDefinition("http://schemas.microsoft.com/winfx/2006/xaml/presentation", "System.Windows.Media")

XmlnsDefinition("http://schemas.microsoft.com/winfx/2006/xaml", "System.Windows.Markup")


2. netfx 영역

XmlnsDefinition("http://schemas.microsoft.com/netfx/2009/xaml/presentation", "System.Windows.Controls")

XmlnsDefinition("http://schemas.microsoft.com/netfx/2009/xaml/presentation", "System.Windows.Navigation")

XmlnsDefinition("http://schemas.microsoft.com/netfx/2007/xaml/presentation", "System.Windows.Documents")

XmlnsDefinition("http://schemas.microsoft.com/netfx/2007/xaml/presentation", "System.Windows.Shapes")

XmlnsDefinition("http://schemas.microsoft.com/netfx/2007/xaml/presentation", "System.Windows.Shell")

XmlnsDefinition("http://schemas.microsoft.com/netfx/2007/xaml/presentation", "System.Windows.Navigation")

XmlnsDefinition("http://schemas.microsoft.com/netfx/2007/xaml/presentation", "System.Windows.Data")

XmlnsDefinition("http://schemas.microsoft.com/netfx/2007/xaml/presentation", "System.Windows")

XmlnsDefinition("http://schemas.microsoft.com/netfx/2007/xaml/presentation","System.Windows.Controls.Primitives")

XmlnsDefinition("http://schemas.microsoft.com/netfx/2007/xaml/presentation","System.Windows.Media.Animation")

XmlnsDefinition("http://schemas.microsoft.com/netfx/2007/xaml/presentation", "System.Windows.Input")

XmlnsDefinition("http://schemas.microsoft.com/netfx/2007/xaml/presentation", "System.Windows.Media")

XmlnsDefinition("http://schemas.microsoft.com/netfx/2009/xaml/presentation", "System.Windows.Shapes")

XmlnsDefinition("http://schemas.microsoft.com/netfx/2009/xaml/presentation", "System.Windows.Shell")

XmlnsDefinition("http://schemas.microsoft.com/netfx/2007/xaml/presentation", "System.Windows.Controls")

XmlnsDefinition("http://schemas.microsoft.com/netfx/2009/xaml/presentation", "System.Windows.Data")

XmlnsDefinition("http://schemas.microsoft.com/netfx/2009/xaml/presentation", "System.Windows")

XmlnsDefinition("http://schemas.microsoft.com/netfx/2009/xaml/presentation","System.Windows.Controls.Primitives")

XmlnsDefinition("http://schemas.microsoft.com/netfx/2009/xaml/presentation","System.Windows.Media.Animation")

XmlnsDefinition("http://schemas.microsoft.com/netfx/2009/xaml/presentation", "System.Windows.Input")

XmlnsDefinition("http://schemas.microsoft.com/netfx/2009/xaml/presentation", "System.Windows.Documents")


3. xps영역

XmlnsDefinition("http://schemas.microsoft.com/xps/2005/06", "System.Windows.Input")

XmlnsDefinition("http://schemas.microsoft.com/xps/2005/06", "System.Windows.Media.Animation")

XmlnsDefinition("http://schemas.microsoft.com/xps/2005/06", "System.Windows.Controls")

XmlnsDefinition("http://schemas.microsoft.com/xps/2005/06", "System.Windows.Documents")

XmlnsDefinition("http://schemas.microsoft.com/xps/2005/06", "System.Windows.Shapes")

XmlnsDefinition("http://schemas.microsoft.com/xps/2005/06", "System.Windows.Navigation")

XmlnsDefinition("http://schemas.microsoft.com/xps/2005/06", "System.Windows.Data")

XmlnsDefinition("http://schemas.microsoft.com/xps/2005/06", "System.Windows")

XmlnsDefinition("http://schemas.microsoft.com/xps/2005/06", "System.Windows.Controls.Primitives")


사실 WPF를 학습하면서 XAML이 어떻게 구성되며, 어떤 네임스페이스를 사용하는지 알아야 하는 경우는 발생하지 않았으나 XAML을 구성하는데 있어서 어떤 네임스페이스를 사용하고 있는지 알아 두는 것도 나쁘지 않을 것 같아 정리 합니다.


XAML 코드에 기본 네임스페이스 말고 다른 네임스페이스를 언제 사용하게 될지 모르기 때문에 말이죠. 


사실 이 정리는 역어셈블을 통해 취득한 내용이므로 이것이 전체 네임스페이스 인지 아닌지는 알 수 없습니다.

아마도 제가 찾지 못했던 MSDN의 어느 구석에는 이 맵핑 정보가 있을지도 모르겠습니다.


OTL... 이 맵핑 정보 하나 알아내는 것도.. 어마 어마한 노력이...... 머리 나쁜 개발자는 점점 더 설곳이 없어지는거 같습니다......... 


http://msdn.microsoft.com/ko-kr/library/ms747086(v=vs.110).aspx

MSDN의 관련 정보 입니다.

Posted by 프로그래머란 카페인을 코드로 변환하는 기계다
,