如何在xaml的资源标签中获取应用程序路径
本文关键字:获取 应用程序 路径 标签 资源 xaml | 更新日期: 2023-09-27 18:11:48
我正在开发一个应用程序,我需要从xml文件中读取数据,并需要在组合框中显示数据。我已经从net的例子和完成的应用程序。但现在我需要从bin或从应用程序启动文件的路径。
<Grid.Resources>
<!--<Path> string currpath ="System.AppDomain.CurrentDomain.BaseDirectory"</Path>-->
<XmlDataProvider x:Key="AppConfig" **Source="Z:''AppConfiguration.xml"** XPath="Configuration"/>
</Grid.Resources>
现在我想从应用程序的路径,文件将被存储的源。
首先定义一个属性用于存储xmlfilepath值
public string xmlfilepath{get;set;}
你可以在后面的代码中获得应用程序的基础目录,并在其中存储一个变量,并使路径的字符串像这样连接
xmlfilepath= System.AppDomain.CurrentDomain.BaseDirectory + "your folder name and file name path will come here";
,然后你可以用路径变量绑定Source属性,就像下面的
<XmlDataProvider x:Key="AppConfig" Source="{Binding xmlfilepath,Mode=Twoway,UpdateSourceTrigger=PropertyChanged}" XPath="Configuration"/>
您可以使用pack://siteoforigin:
或pack://application:
。例如:
<Image Source="pack://siteoforigin:,,,/Resources/Logo.png" />