4
<appSettings>
  <add key="inactivity_interval" value="10" />
  <add key="maximumHeightPopUp" value="260" />
  <add key="horizontalArrowsHeight" value="35" />
  <add key="modelsListHeight" value="100" />
</appSettings>

I want to use part of this settings in the xaml for example to set grid height. Is it possible?

User9898
  • 251
  • 1
  • 3
  • 11

3 Answers3

1

Yes you can do it,with using System.Configuration

ConfigurationManager.AppSettings["inactivity_interval"]; 

will return value.

for more check this

Community
  • 1
  • 1
Zergling
  • 526
  • 2
  • 7
1

In your app.config define like below:

<applicationSettings>
  <MyApplication.Properties.Settings>
      <setting name="inactivity_interval" serializeAs="String">
        <value>16</value>
      </setting>
    <MyApplication.Properties.Settings>
  </applicationSettings>

Then in your xaml file refer namespace :

xmlns:p="clr-namespace:MyApplication.Properties"

and invoke the config values like below:

Value="{Binding Source={x:Static p:Settings.Default}, Path=inactivity_interval}"
Mayank Tripathi
  • 809
  • 1
  • 7
  • 11
  • I tried this but it looks for the value in Settings.settings. If I have resharper add the missing property it adds a C# property to Settings.Designer.cs. My, I'd forgotten how obtuse xaml/wpf is. – Fredrick Jul 08 '23 at 01:44
0

In your app.config change your appsetting to

<applicationSettings>
    <WpfApplication1.Properties.Settings>
        <setting name="inactivity_interval" serializeAs="String">
            <value>10</value>
        </setting>
        <setting name="maximumHeightPopUp" serializeAs="String">
            <value>260</value>
        </setting>
        <setting name="horizontalArrowsHeight" serializeAs="String">
            <value>35</value>
        </setting>
        <setting name="modelsListHeight" serializeAs="String">
            <value>100</value>
        </setting>
    </WpfApplication1.Properties.Settings>
</applicationSettings>

Then in code-behind C# for retrive values:

string inc_interval = WpfApplication1.Properties.Settings.Default.inactivity_interval.ToString();
string maximumHeightPopUp = WpfApplication1.Properties.Settings.Default.maximumHeightPopUp.ToString();
string horizontalArrowsHeight = WpfApplication1.Properties.Settings.Default.horizontalArrowsHeight.ToString();
string modelsListHeight= WpfApplication1.Properties.Settings.Default.modelsListHeight.ToString();
rdn87
  • 739
  • 5
  • 18