wpf Assembly.LoadFile dll GetType 反射 抛异常 不具有由 URI 识别的资源。
public static void LoadViewFromUri(this Window window, string baseUri)
{
try
{
var resourceLocater = new Uri(baseUri, UriKind.Relative);
var exprCa = (PackagePart)typeof(Application).GetMethod("GetResourceOrContentPart", BindingFlags.NonPublic | BindingFlags.Static).Invoke(null, new object[] { resourceLocater });
var stream = exprCa.GetStream();
var uri = new Uri((Uri)typeof(BaseUriHelper).GetProperty("PackAppBaseUri", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null, null), resourceLocater);
var parserContext = new ParserContext
{
BaseUri = uri
};
typeof(XamlReader).GetMethod("LoadBaml", BindingFlags.NonPublic | BindingFlags.Static).Invoke(null, new object[] { stream, parserContext, window, true });
}
catch (Exception)
{
//log
}
}
public partial class WinEditPedestrianNormalDeploy : Window { public WinEditPedestrianNormalDeploy() { //InitializeComponent();//屏蔽 this.LoadViewFromUri("/Harzone.VideoData.RetrieveObjects;component/view/windows/wineditpedestriannormaldeploy.xaml"); } }
posted on 2018-07-05 14:33 Shine-Zhong 阅读(905) 评论(0) 收藏 举报
浙公网安备 33010602011771号