[英]Custom Source for XmlDataProvider in WPF
I have the following in my app. 我的应用程序中包含以下内容。 config file
配置文件
<appSettings>
<add key="Path" value="C:\Users\dave\Desktop\dave"/>
</appSettings>
in my XAML file, the XmlDataProvider is as follows: 在我的XAML文件中,XmlDataProvider如下:
<XmlDataProvider x:Name="Data" Source= "setting.xml" XPath="Product" />
I would like to point the Source to Path. 我想将Source指向Path。
Any help as always is much appreciated. 一如既往的任何帮助,我们深表感谢。
Kind regards 亲切的问候
if you dont mind having a property in code behind, you can use StringFormat
in the xaml 如果您不介意后面的代码中有属性,则可以在xaml中使用
StringFormat
public string MyPath
{
get { return ConfigurationManager.AppSettings["Path"]; }
}
<XmlDataProvider x:Name="Data" Source="{Binding Path=MyPath, StringFormat={}{0}\\Settings.xml}" XPath="Product" />
returns: "C:\\Users\\dave\\Desktop\\dave\\Settings.xml" 返回:“ C:\\ Users \\ dave \\ Desktop \\ dave \\ Settings.xml”
Try like this: 尝试这样:
<XmlDataProvider x:Name="Data" Source= "pack://siteoforigin:,,,/setting.xml" XPath="Product" />
setting.xml must be in your main folder. setting.xml必须在您的主文件夹中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.