4
내 프로젝트에 xaml 파일이 Ns1\Ns2\myfile.xaml
에 있습니다. 빌드 동작은 MSBuild : Compile의 사용자 지정 도구를 사용하여 Page로 설정됩니다. 나는 정적 생성자에서이 파일을로드하기 위해 노력하고있어 :Application.LoadComponent가 리소스를 찾을 수 없습니다.
namespace Ns1.Ns2 {
internal class MyClass {
static() {
var obj = Application.LoadComponent(new Uri("/myfile.xaml", UriKind.Relative));
}
}
}
을 그러나, 나는이 코드를 실행하려고 할 때, 그것은 예외 cannot locate resource 'myfile.xaml'
와 함께 실패합니다. URI를 절대 URI로 변경하면 Cannot use absolute URI
으로 실패합니다. myfile.xaml의 유형을 자원으로 변경하면 동일한 오류가 발생합니다.
코드에서 myfile.xaml을 컴파일하고 참조하려면 어떻게해야합니까? 파일이 코드 숨김 클래스, 당신은 단지 '새로운'그것하고, 생성 된 코드는 관련 XAML을로드 할 수있는 경우, 또는
Application.LoadComponent(new Uri("/AssemblyName;component/myfile.xaml", UriKind.Relative))
:
이 경우'/ WpfApplication1; ns1/ns2/myfile.xaml'이 될 것입니까? 그건 작동하지 않습니다. – thecoop
@thecoop 구성 요소를 지정하는 것을 잊었다 고 생각합니다. – ethicallogics
아, 그게 경로의 일부가 아니에요? 알았다. – thecoop