0

Iam developing an application where i need to read data from an xml file and need to show the data in a combobox. I have followed the example from net and completed the application. But now i need the path of the file from a the bin or from the application startup.

   <Grid.Resources>
        <!--<Path> string currpath ="System.AppDomain.CurrentDomain.BaseDirectory"</Path>-->
            <XmlDataProvider x:Key="AppConfig" **Source="Z:\\AppConfiguration.xml"** XPath="Configuration"/>

    </Grid.Resources>

Now i want Source from the application path where the file will be stored. Thanks in advance.

user3750815
  • 1
  • 1
  • 3

2 Answers2

0

first define one property for storing xmlfilepath value

public string xmlfilepath{get;set;}

you can get application base directory in code behind and store in it one variable and make concated string of path like this

xmlfilepath= System.AppDomain.CurrentDomain.BaseDirectory + "your folder name and file name path will come here";

and then you can bind Source property with path variable like below

<XmlDataProvider x:Key="AppConfig" Source="{Binding xmlfilepath,Mode=Twoway,UpdateSourceTrigger=PropertyChanged}" XPath="Configuration"/>
Ashok Rathod
  • 840
  • 9
  • 24
  • Hi Thanks for the response. i have tried the code you gave but its giving an error Error 1 A 'Binding' cannot be set on the 'Source' property of type 'XmlDataProvider'. A 'Binding' can only be set on a DependencyProperty of a DependencyObject. – user3750815 Jul 07 '14 at 09:23
  • 1
    @AshokRathod He just stated that it does not work.. Why should he then mark it as an answer? – default Jul 07 '14 at 09:51
  • in that case i would suggest u direclty bind xml file to your required control like done in below stated example http://stackoverflow.com/questions/1866942/how-to-bind-xmldataprovider-source-to-mvvm-property – Ashok Rathod Jul 07 '14 at 09:57
0

You can use pack://siteoforigin: or pack://application:. For example:

<Image Source="pack://siteoforigin:,,,/Resources/Logo.png" />
shfire
  • 837
  • 7
  • 7
  • Those two are not the same :) See:http://stackoverflow.com/questions/6043138/what-is-applications-site-of-origin-and-when-to-use-it – Wahyu Apr 22 '16 at 09:19