Link to home
Start Free TrialLog in
Avatar of marktoth
marktoth

asked on

Access a connectionstring from app.config in xaml file for WPF application

I want to access a connection string defined in my app.config file to initialize a control in a .xaml file in a WPF appliction but can't quite figure out how to do it.  I could set the value in the loaded event but I really want to keep all the initialization together in the .xaml file.

Below is my app.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <connectionStrings>
    <add name="OracleConnectionString" connectionString="Data Source=XXXXX;Persist Security Info=True;User ID=XXXXX;Password=XXXXX Max Pool Size=400"
      providerName="System.Data.OracleClient" />
  </connectionStrings>
  <appSettings>
    <add key="DefaultAuctionID" value="304"/>
  </appSettings>
</configuration>

and here is an example of a customer user control I wrote that has a connection string property exposed.

<bs:PriceStats AuctionID="304" Width="Auto" Height="Auto"
                                    ConnectionString="Data Source=XXXXXX;Persist Security Info=True;User ID=XXXX;Password=XXXXX; Max Pool Size=400"></bs:PriceStats>
                         

I want to be able to access the connectionstring and the DefaultAuctionID from the app.config in the .xaml file.
Avatar of Meir Rivkin
Meir Rivkin
Flag of Israel image

do u want to get the connectionstring value from the app.config programatically?
Here's how to get it programmatically...  Looking around for how to access it in xaml.

    http://www.tanguay.info/web/index.php?pg=howtos&id=20



ASKER CERTIFIED SOLUTION
Avatar of VBRocks
VBRocks
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of marktoth
marktoth

ASKER

done