Click here to Skip to main content
15,893,161 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Dear All,
I'm new in WPF and I will bind in the XAML code the content of a label with a parameter stored in the app.config. I work around and cannot do it.
I have in app.config :
XML
<configuration>
  <appSettings>
    <add key="Title" value="EndPoint Supervisor 2"/>
  </appSettings>
</configuration>



and I would like this binding in my label :
CSS
<Label Grid.Column="1"
                    Name="LabelTitle"
                    Content="{Binding ???}" />


With what code must I replace ???? to have a binding with the key "Title".
Thank in advance.
Posted

1 solution

The application settings cannot be bound directly. You can however introduce an intermidiate model that wraps the application settings.

For example:

public class ConfigurationSettings {
    public string Title { 
        get { return ConfigurationManager.AppSettings["Title"] as String; }
    }
}


Then you can bind this model to your view and use the following binding expression to get a hold of the title.

<label text="{Binding Title}" ...="" />
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900