装配资源+所选项目 [英] Assembly Resource + selected item

查看:56
本文介绍了装配资源+所选项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好。我有这段代码

<前lang =c#> 私人 void TreeViewItem_Selected( object sender,RoutedEventArgs e)
{
Assembly assembly = Assembly。 GetExecutingAssembly();
string NAME = WpfApplication2.Res。 Pages。 + treeView1.Name + 。xaml;

使用(Stream stream = assembly .GetManifestResourceStream(NAME))
{
FlowDocument document =(FlowDocument)XamlReader.Load(stream);
flow.Document = document;
}
}





编译后我从treeView中选择项目并获取此行的ArgumentNullException

 FlowDocument document =(FlowDocument)XamlReader.Load(stream); 





如何解决?谢谢

解决方案

使用如下,

 使用(Stream stream =  assembly  .GetManifestResourceStream( this  .GetType(),NAME))
{
FlowDocument document =(FlowDocument)XamlReader.Load(stream);
flow.Document = document;
}





这里我刚改变了

  assembly  .GetManifestResourceStream(NAME)



to

  assembly  .GetManifestResourceStream( this  .GetType(),NAME)


Hello. I have this code

private void TreeViewItem_Selected(object sender, RoutedEventArgs e)
{
     Assembly assembly = Assembly.GetExecutingAssembly();
     string NAME = "WpfApplication2.Res.Pages."+treeView1.Name+".xaml";

    using (Stream stream = assembly.GetManifestResourceStream(NAME))
    {
        FlowDocument document = (FlowDocument)XamlReader.Load(stream);
        flow.Document = document;
    }
}



After compiling I choose item from treeView and get ArgumentNullException for this line

FlowDocument document = (FlowDocument)XamlReader.Load(stream);



How to fix it? Thank you

解决方案

Use as follows,

using (Stream stream = assembly.GetManifestResourceStream(this.GetType(), NAME))
{
   FlowDocument document = (FlowDocument)XamlReader.Load(stream);
   flow.Document = document;
}



Here I just changed

assembly.GetManifestResourceStream(NAME)


to

assembly.GetManifestResourceStream(this.GetType(), NAME)


这篇关于装配资源+所选项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆