如何在运行时更改xmldataprovider源WPF? [英] how to change xmldataprovider source in wpf at runtime?
本文介绍了如何在运行时更改xmldataprovider源WPF?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我做了哪些借鉴的基础上,从一个XML文件中的值组织的树中的应用程序
I made an application which draws a tree of organization based on values from an xml file.
XAML文件是这样的:
The xaml file goes like this :
<Window.Resources>
<!-- The Org Chart Data-->
<XmlDataProvider x:Key="organization" Source="model.xml" />
<SolidColorBrush x:Key="ListBorder" Color="#FF7F9DB9"/>
<!-- The Style for Nodes -->
<Style TargetType="{x:Type draw:Node}">
<Setter Property="OverridesDefaultStyle" Value="true"/>
<Setter Property="Template">
---------------------------------------------------------
我希望能够改变源在通过选择一个XML文件,从打开文件对话框(如按钮单击)运行时我该怎么办呢?
I want to be able to change the source at runtime by selecting a xml file from openfiledialog (like button click) how do i do that?
推荐答案
您可以得到 XmlDataProvider
实例通过写(XmlDataProvider)this.Resources [组织]
中的代码文件。
You can get the XmlDataProvider
instance by writing (XmlDataProvider)this.Resources["organization"]
in the code file.
您可以再设置的 来源
属性从一个文件对话框的路径
You can then set the Source
property to a path from a file dialog.
例如:
var provider = (XmlDataProvider)this.Resources["organization"];
var dialog = new OpenFileDialog();
dialog.Filter = "XML Files|*.xml";
if (dialog.ShowDialog(this)) {
provider.Source = new Uri(dialog.FileName, UriKind.Absolute);
这篇关于如何在运行时更改xmldataprovider源WPF?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文