• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5296
  • Last Modified:

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.
0
marktoth
Asked:
marktoth
  • 2
1 Solution
 
Meir RivkinFull stack Software EngineerCommented:
do u want to get the connectionstring value from the app.config programatically?
0
 
VBRocksCommented:
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



0
 
VBRocksCommented:
Take a look at this link for informaiton on how it can be accomplished in xaml:

    http://weblogs.asp.net/psheriff/archive/2009/10/19/binding-to-config-settings-in-wpf.aspx

0
 
marktothAuthor Commented:
done
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now