NUI/Microsoft PixelSense(Old Surface)

[WPF] 외부 라이브러리에 만든 Generic.xaml이 제대로 로딩되지 않을 때 해줄 일

길버트리 2012. 7. 30. 20:57

Custom Control이 기본 스타일을 입지 않는다...

Custom Control을 라이브러리에 만들어 사용할 때, 실버라이트에서는 이런 일이 없었는데, WPF에서는 매번 발생하네요.

 

그 동안 어플리케이션 프로젝트에 기본 컨트롤 스타일을 복사해서 사용하는 허접한 Workaround를 사용하고 있다가,

계속 이러면 안 되겠다 싶어. 열심히 구글링 해 본 결과 다음 포스트를 찾을 수 있었습니다.

 

J# Microsoft MVP인 George Birbilis의 "What to do if Generic.xaml doesn’t get loaded for WPF control"

 

처치방법

처치방법을 요약하면 다음과 같습니다.

 

커스텀컨트롤이 속한 라이브러리 프로젝트에서 Properties 노드 밑에 숨어있는 AssemblyInfo.cs를 열어,

1) 최상단에 using System.Windows;를 추가해 주고,

2) 최하단에 다음 코드를 추가하면 됩니다.

[assembly: ThemeInfo(
    ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located 
    //(used if a resource is not found in the page, 
    // or application resource dictionaries) 
    ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located 
    //(used if a resource is not found in the page, 
    // app, or any theme specific resource dictionaries) 
)]

 

이러고나니 커스텀컨트롤의 OnApplyTemplate 이하 코드에 걸어놓은 중단점에서 디버그 포인트가 걸리네요.

앓던 이를 뽑은 듯 시원합니다.