성태의 닷넷 이야기
홈 주인
모아 놓은 자료
프로그래밍
질문/답변
사용자 관리
사용자
메뉴
아티클
외부 아티클
유용한 코드
온라인 기능
MathJax 입력기
최근 덧글
[정성태] Roll A Lisp In C - Reading ; https...
[정성태] Java - How to use the Foreign Funct...
[정성태] 제가 큰 실수를 했군요. ^^; Delegate를 통한 Bein...
[정성태] Working with Rust Libraries from C#...
[정성태] Detecting blocking calls using asyn...
[정성태] 아쉽게도, 커뮤니티는 아니고 개인 블로그입니다. ^^
[정성태] 질문이 잘 이해가 안 됩니다. 우선, 해당 소스코드에서 ILis...
[양승조
] var대신 dinamic으로 선언해서 해결은 했습니다. 맞는 해...
[양승조
] 또 막혔습니다. ㅠㅠ var list = props[i].Ge...
[양승조
] 아. 감사합니다. 어제는 안됐던것 같은데....정신을 차려야겠네...
글쓰기
제목
이름
암호
전자우편
HTML
홈페이지
유형
제니퍼 .NET
닷넷
COM 개체 관련
스크립트
VC++
VS.NET IDE
Windows
Team Foundation Server
디버깅 기술
오류 유형
개발 환경 구성
웹
기타
Linux
Java
DDK
Math
Phone
Graphics
사물인터넷
부모글 보이기/감추기
내용
<div style='display: inline'> <h1 style='font-family: Malgun Gothic, Consolas; font-size: 20pt; color: #006699; text-align: center; font-weight: bold'>WPF에서 d:DesignHeight 값을 구할 수 있을까?</h1> <p> 이 글도 ^^ 데브피아 Q&A 덕분에 쓰게 되는 것입니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > xaml 디자인상의 size를 코드에서 알수 있나요? ; <a target='tab' href='http://www.devpia.com/MAEUL/Contents/Detail.aspx?BoardID=80&MAEULNO=2&no=2080&ref=2080'>http://www.devpia.com/MAEUL/Contents/Detail.aspx?BoardID=80&MAEULNO=2&no=2080&ref=2080</a> </pre> <br /> XAML에 대한 디자인 화면에서의 크기는 다음과 같은 속성으로 표현되어 있습니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > <UserControl x:Class="WpfApplication1.UserControl1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" <span style='color: blue; font-weight: bold'>xmlns:d="http://schemas.microsoft.com/expression/blend/2008" </span> <span style='color: blue; font-weight: bold'>mc:Ignorable="d" d:DesignHeight="182" d:DesignWidth="348"></span> </pre> <br /> 이 값을 실행시에 구하는 것이 가능하냐는 의미가 되는데요. 가능할까요? ^^<br /> <br /> 처음에 저는, 그 속성들이 정의된 타입을 알아내면 될 것이라고 생각해서 "xmlns:d"를 정의한 네임스페이스를 먼저 찾아야 한다고 생각했습니다. WPF 공부를 어느 정도 하셨다면 다음의 네임스페이스 정의가 이와 관련되었음을 아실 텐데요.<br /> <br /> <ul> <li>XmlnsDefinitionAttribute</li> <li>XmlnsPrefixAttribute</li> </ul> <br /> 위의 글에 대해서는 다음의 글에서 설명해 놓았으니 참고하시고. ^^<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > WPF - XAML 요소의 네임스페이스와 CLR 타입 매핑 ; <a target='tab' href='http://www.sysnet.pe.kr/2/0/793'>http://www.sysnet.pe.kr/2/0/793</a> </pre> <br /> 그렇다면, 정상적인 경우라면 아마도 다음과 같은 정의를 포함하고 있는 어셈블리가 있을 것입니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > [assembly: XmlnsPrefix("http://schemas.microsoft.com/expression/blend/2008", "d")] [assembly: XmlnsDefinition("http://schemas.microsoft.com/expression/blend/2008", "...")] </pre> <br /> .NET Reflector로 모든 어셈블리를 찾아보면 나오겠지만, 어차피 "assembly" 특성이 적용된 것이기 때문에 다음과 같은 코드로 찾아내는 것도 가능합니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > AppDomain currentDomain = AppDomain.CurrentDomain; foreach (Assembly asm in currentDomain.GetAssemblies()) { foreach (object obj in asm.<span style='color: blue; font-weight: bold'>GetCustomAttributes(typeof(XmlnsDefinitionAttribute)</span>, true)) { XmlnsDefinitionAttribute attr = obj as XmlnsDefinitionAttribute; if (attr == null) { continue; } System.Diagnostics.Trace.WriteLine(attr.XmlNamespace + " == " + attr.ClrNamespace); } foreach (object obj in asm.<span style='color: blue; font-weight: bold'>GetCustomAttributes(typeof(XmlnsPrefixAttribute)</span>, true)) { XmlnsPrefixAttribute attr = obj as XmlnsPrefixAttribute; if (attr == null) { continue; } System.Diagnostics.Trace.WriteLine(attr.XmlNamespace + " == " + attr.Prefix); } } </pre> <br /> 그런데, 이상하군요. "http://schemas.microsoft.com/expression/blend/2008" 네임스페이스 관련한 정의가 WPF 응용 프로그램을 실행시 로드된 DLL 에는 존재하지 않았습니다.<br /> <br /> <pre style='height: 400px; margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > http://schemas.microsoft.com/netfx/2009/xaml/presentation == System.Windows.Shapes http://schemas.microsoft.com/xps/2005/06 == System.Windows.Controls.Primitives http://schemas.microsoft.com/xps/2005/06 == System.Windows.Input http://schemas.microsoft.com/xps/2005/06/documentstructure == System.Windows.Documents.DocumentStructures http://schemas.microsoft.com/winfx/2006/xaml/presentation == System.Windows.Controls http://schemas.microsoft.com/winfx/2006/xaml/presentation == System.Windows.Documents http://schemas.microsoft.com/winfx/2006/xaml/presentation == System.Windows.Shapes http://schemas.microsoft.com/winfx/2006/xaml/presentation == System.Windows.Shell http://schemas.microsoft.com/winfx/2006/xaml/presentation == System.Windows.Navigation http://schemas.microsoft.com/winfx/2006/xaml/presentation == System.Windows.Data http://schemas.microsoft.com/winfx/2006/xaml/presentation == System.Windows http://schemas.microsoft.com/winfx/2006/xaml/presentation == System.Windows.Controls.Primitives http://schemas.microsoft.com/winfx/2006/xaml/presentation == System.Windows.Media.Animation http://schemas.microsoft.com/winfx/2006/xaml/presentation == System.Windows.Input http://schemas.microsoft.com/winfx/2006/xaml/presentation == System.Windows.Media http://schemas.microsoft.com/netfx/2007/xaml/presentation == System.Windows.Controls http://schemas.microsoft.com/netfx/2007/xaml/presentation == System.Windows.Documents http://schemas.microsoft.com/netfx/2007/xaml/presentation == System.Windows.Shapes http://schemas.microsoft.com/netfx/2007/xaml/presentation == System.Windows.Shell http://schemas.microsoft.com/netfx/2007/xaml/presentation == System.Windows.Navigation http://schemas.microsoft.com/netfx/2007/xaml/presentation == System.Windows.Data http://schemas.microsoft.com/netfx/2007/xaml/presentation == System.Windows http://schemas.microsoft.com/netfx/2007/xaml/presentation == System.Windows.Controls.Primitives http://schemas.microsoft.com/netfx/2007/xaml/presentation == System.Windows.Media.Animation http://schemas.microsoft.com/netfx/2007/xaml/presentation == System.Windows.Input http://schemas.microsoft.com/netfx/2007/xaml/presentation == System.Windows.Media http://schemas.microsoft.com/netfx/2009/xaml/presentation == System.Windows.Controls http://schemas.microsoft.com/netfx/2009/xaml/presentation == System.Windows.Documents http://schemas.microsoft.com/xps/2005/06 == System.Windows.Media.Animation http://schemas.microsoft.com/netfx/2009/xaml/presentation == System.Windows.Shell http://schemas.microsoft.com/netfx/2009/xaml/presentation == System.Windows.Navigation http://schemas.microsoft.com/netfx/2009/xaml/presentation == System.Windows.Data http://schemas.microsoft.com/netfx/2009/xaml/presentation == System.Windows http://schemas.microsoft.com/netfx/2009/xaml/presentation == System.Windows.Controls.Primitives http://schemas.microsoft.com/netfx/2009/xaml/presentation == System.Windows.Media.Animation http://schemas.microsoft.com/netfx/2009/xaml/presentation == System.Windows.Input http://schemas.microsoft.com/winfx/2006/xaml == System.Windows.Markup http://schemas.microsoft.com/xps/2005/06 == System.Windows.Controls http://schemas.microsoft.com/xps/2005/06 == System.Windows.Documents http://schemas.microsoft.com/xps/2005/06 == System.Windows.Shapes http://schemas.microsoft.com/xps/2005/06 == System.Windows.Navigation http://schemas.microsoft.com/xps/2005/06 == System.Windows.Data http://schemas.microsoft.com/xps/2005/06 == System.Windows http://schemas.microsoft.com/xps/2005/06 == metro http://schemas.microsoft.com/winfx/2006/xaml/presentation == av http://schemas.microsoft.com/netfx/2007/xaml/presentation == wpf http://schemas.microsoft.com/netfx/2009/xaml/presentation == wpf http://schemas.microsoft.com/winfx/2006/xaml == x http://schemas.microsoft.com/winfx/2006/xaml/presentation == System.Windows.Input http://schemas.microsoft.com/netfx/2007/xaml/presentation == System.Windows http://schemas.microsoft.com/winfx/2006/xaml/presentation == System.Diagnostics http://schemas.microsoft.com/netfx/2007/xaml/presentation == System.Windows.Media http://schemas.microsoft.com/winfx/2006/xaml/presentation == System.Windows.Media http://schemas.microsoft.com/winfx/2006/xaml/composite-font == System.Windows.Media http://schemas.microsoft.com/winfx/2006/xaml == System.Windows.Markup http://schemas.microsoft.com/winfx/2006/xaml/presentation == System.Windows http://schemas.microsoft.com/xps/2005/06 == System.Windows.Media http://schemas.microsoft.com/xps/2005/06 == System.Windows.Input http://schemas.microsoft.com/xps/2005/06 == System.Windows http://schemas.microsoft.com/netfx/2009/xaml/presentation == System.Diagnostics http://schemas.microsoft.com/netfx/2007/xaml/presentation == System.Windows.Input http://schemas.microsoft.com/netfx/2009/xaml/presentation == System.Windows.Media http://schemas.microsoft.com/netfx/2009/xaml/presentation == System.Windows.Input http://schemas.microsoft.com/netfx/2009/xaml/presentation == System.Windows http://schemas.microsoft.com/netfx/2007/xaml/presentation == System.Diagnostics http://schemas.microsoft.com/xps/2005/06 == metro http://schemas.microsoft.com/winfx/2006/xaml/presentation == av http://schemas.microsoft.com/netfx/2009/xaml/presentation == wpf http://schemas.microsoft.com/netfx/2007/xaml/presentation == wpf http://schemas.microsoft.com/xps/2005/06 == System.Windows.Input http://schemas.microsoft.com/winfx/2006/xaml/presentation == System.Windows http://schemas.microsoft.com/netfx/2009/xaml/presentation == System.Windows http://schemas.microsoft.com/netfx/2007/xaml/presentation == System.Windows http://schemas.microsoft.com/netfx/2009/xaml/presentation == System.Windows.Media http://schemas.microsoft.com/netfx/2007/xaml/presentation == System.Windows.Media.Animation http://schemas.microsoft.com/xps/2005/06 == System.Windows http://schemas.microsoft.com/winfx/2006/xaml/presentation == System.Windows.Media http://schemas.microsoft.com/winfx/2006/xaml/presentation == System.Windows.Media.Media3D http://schemas.microsoft.com/netfx/2007/xaml/presentation == System.Windows.Input http://schemas.microsoft.com/netfx/2007/xaml/presentation == System.Windows.Automation http://schemas.microsoft.com/netfx/2007/xaml/presentation == System.Windows.Media.Effects http://schemas.microsoft.com/netfx/2007/xaml/presentation == System.Windows.Media.Imaging http://schemas.microsoft.com/winfx/2006/xaml/presentation == System.Windows.Ink http://schemas.microsoft.com/winfx/2006/xaml/presentation == System.Windows.Input http://schemas.microsoft.com/netfx/2009/xaml/presentation == System.Windows.Media.Animation http://schemas.microsoft.com/netfx/2007/xaml/presentation == System.Windows.Media.Media3D http://schemas.microsoft.com/xps/2005/06 == System.Windows.Automation http://schemas.microsoft.com/netfx/2007/xaml/presentation == System.Windows.Media.TextFormatting http://schemas.microsoft.com/xps/2005/06 == System.Windows.Media.TextFormatting http://schemas.microsoft.com/xps/2005/06 == System.Windows.Media.Effects http://schemas.microsoft.com/xps/2005/06 == System.Windows.Media.Imaging http://schemas.microsoft.com/xps/2005/06 == System.Windows.Media.Animation http://schemas.microsoft.com/winfx/2006/xaml/composite-font == System.Windows.Media http://schemas.microsoft.com/winfx/2006/xaml/presentation == System.Windows.Automation http://schemas.microsoft.com/winfx/2006/xaml/presentation == System.Windows.Media.TextFormatting http://schemas.microsoft.com/xps/2005/06 == System.Windows.Media.Media3D http://schemas.microsoft.com/netfx/2007/xaml/presentation == System.Windows.Media http://schemas.microsoft.com/winfx/2006/xaml/presentation == System.Windows.Media.Effects http://schemas.microsoft.com/winfx/2006/xaml/presentation == System.Windows.Media.Imaging http://schemas.microsoft.com/winfx/2006/xaml/presentation == System.Windows.Media.Animation http://schemas.microsoft.com/netfx/2007/xaml/presentation == System.Windows.Ink http://schemas.microsoft.com/winfx/2006/xaml == System.Windows.Markup http://schemas.microsoft.com/netfx/2009/xaml/presentation == System.Windows.Ink http://schemas.microsoft.com/xps/2005/06 == System.Windows.Media http://schemas.microsoft.com/netfx/2009/xaml/presentation == System.Windows.Automation http://schemas.microsoft.com/netfx/2009/xaml/presentation == System.Windows.Input http://schemas.microsoft.com/netfx/2009/xaml/presentation == System.Windows.Media.TextFormatting http://schemas.microsoft.com/netfx/2009/xaml/presentation == System.Windows.Media.Effects http://schemas.microsoft.com/netfx/2009/xaml/presentation == System.Windows.Media.Imaging http://schemas.microsoft.com/netfx/2009/xaml/presentation == System.Windows.Media.Media3D http://schemas.microsoft.com/winfx/2006/xaml == x http://schemas.microsoft.com/netfx/2007/xaml/presentation == wpf http://schemas.microsoft.com/xps/2005/06 == xps http://schemas.microsoft.com/winfx/2006/xaml/presentation == av http://schemas.microsoft.com/netfx/2009/xaml/presentation == wpf http://schemas.microsoft.com/winfx/2006/xaml == System.Windows.Markup </pre> <br /> 오호~~~ 이게 어찌된 일일까요? 혹시 Visual Studio 내에서만 로드된 DLL 중에 정의된 것일까요?<br /> <br /> 어쨌든, 일단 다른 DLL에 있을지도/없을지도 모르는 것을 조사하는 것은 여기서 끝내고, 다른 조사 방법을 생각해내었습니다.<br /> <br /> 즉, 과연 d:DesignHeight="182" d:DesignWidth="348" 속성값들이 그것을 정의한 WPF 구성요소가 컴파일 된 결과물에 있을까 하는 것이었습니다.<br /> <br /> 그래서, 컴파일 된 빌드 결과물로부터 XAML을 추출해야만 했는데, 이에 대해서는 다음의 글에서 참고했습니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > Extract XAML tool ; <a target='tab' href='http://www.11011.net/archives/000634.html'>http://www.11011.net/archives/000634.html</a> </pre> <br /> 코드가 간단한데요, 직접 해당 컨트롤 내에서 다음과 같은 코드를 실행하면 됩니다. ^^<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > object obj = Activator.CreateInstance(typeof(UserControl1)); System.Windows.Markup.IAddChild window = new System.Windows.Window(); window.AddChild(obj); System.Windows.Markup.XamlWriter.Save(obj, System.Console.Error); </pre> <br /> 결과는 "d:..." 속성 값들이 보이지 않았습니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > <UserControl1 xmlns="clr-namespace:WpfApplication1;assembly=WpfApplication1" xmlns:av="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> <av:Grid Background="#FF000000"> <av:Button Name="button1" Width="75" Height="23" Margin="12,12,0,0" HorizontalAlignment="Left" VerticalAlignment="Top"> Button </av:Button> </av:Grid> </UserControl1> </pre> <br /> 그렇다면, 이 쯤에서 질문에 대한 답이 나왔습니다. 아쉽게도 "d:..." 속성 값들은 런타임 시에 구할 수 없습니다.<br /> <br /> <hr style='width: 50%' /><br /> <br /> 여기서 한 가지 궁금한 점이 다시 생겼습니다. 그렇다면 d:DesignHeight 값이 정의된 어셈블리가 정말 있기라도 한 것일까요? 아니면, mc:Ignorable="d" 구문 때문에 컴파일 시에 "d:..." 속성 값들이 누락되어 DLL/EXE 파일이 생성되는 것일까요?<br /> <br /> 이를 위해, 임의로 다음과 같이 네임스페이스를 추가하고 "mc:Ignorable"에 추가해 보았습니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > <UserControl x:Class="WpfApplication1.UserControl1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" <span style='color: blue; font-weight: bold'>xmlns:test="http://my.namespace.com"</span> mc:Ignorable="d <span style='color: blue; font-weight: bold'>test</span>" d:DesignHeight="182" d:DesignWidth="347" <span style='color: blue; font-weight: bold'>test:TestMode="true"</span> > </pre> <br /> 아하~~~ ^^ 이렇게 정의해도 빌드하는 경우 오류 하나 없이 정상적으로 DLL/EXE가 생성되었습니다.<br /> <br /> 그렇군요. 결국 "d:DesignHeight", "d:DesignWidth" 값들은 소스 코드에만 포함되어 있는 것이고 Visual Studio나 Expression Blend에서는 이 값들을 얻어내서 디자인 화면에서 이용하는 것입니다. 빌드 후에는 없어지고!<br /> </p><br /> <br /><hr /><span style='color: Maroon'>[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]</span> </div>
첨부파일
스팸 방지용 인증 번호
1637
(왼쪽의 숫자를 입력해야 합니다.)