C# 代码隐藏中的数据绑定
我想将 Xml 文件与 C# 代码隐藏绑定。 也就是说,我不想打开下面代码片段所示的文件,而是使用 带有 Xml 文件名的嵌入到项目解决方案中的 Xml 文件。
你能说一下我该怎么做吗?
XmlDataProvider provider = new XmlDataProvider();
if (provider != null)
{
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
doc.Load(fileName);
provider.Document = doc;
provider.XPath = "/opml/body/outline";
FeedListTreeView.DataContext = provider;
}
I would like to bind an Xml file with C# codebehind.
That is, instead of opening a file as shown in the below code snippet, I would like to use
an Xml file embedded into project solution with an Xml filename.
Could you say how I can do this.
XmlDataProvider provider = new XmlDataProvider();
if (provider != null)
{
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
doc.Load(fileName);
provider.Document = doc;
provider.XPath = "/opml/body/outline";
FeedListTreeView.DataContext = provider;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您已在 Visual Studio 中将该文件标记为“嵌入资源”,则本文将显示您可以从程序集中加载它。要记住的主要一点是,您需要使用“.”,而不是通常在文件路径中使用的“\”字符。特点。
如果您尝试从文件系统读取它,那么本文将为您指明方向。
if you have marked the file as an "embedded resource" in Visual Studio, then this article will show you the way to load it form your assembly. The main thing to keep in mind is that instead of the "\" character that you normally use in the path to a file, you want to use the "." character.
if you are trying to read it from the file system, then this article will show you the way.