wpf Assembly.LoadFile dll GetType 反射 抛异常 不具有由 URI 识别的资源。

2018/07/05 14:33
阅读数 1.2K
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");
        }
    }

 

  

展开阅读全文
wpf
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部