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

Posted on 2010-01-06
Last Modified: 2013-11-12
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" ?>
    <add name="OracleConnectionString" connectionString="Data Source=XXXXX;Persist Security Info=True;User ID=XXXXX;Password=XXXXX Max Pool Size=400"
      providerName="System.Data.OracleClient" />
    <add key="DefaultAuctionID" value="304"/>

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.
Question by:marktoth
    LVL 42

    Expert Comment

    do u want to get the connectionstring value from the app.config programatically?
    LVL 27

    Expert Comment

    Here's how to get it programmatically...  Looking around for how to access it in xaml.

    LVL 27

    Accepted Solution

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

    LVL 1

    Author Closing Comment


    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
    Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
    This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now