在xaml wpf中使用app.config设置

时间:2016-01-18 11:14:47

标签: c# wpf xaml

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

我想在xaml中使用此设置的一部分来设置网格高度。 有可能吗?

3 个答案:

答案 0 :(得分:1)

是的,你可以使用System.Configuration

来做到这一点
ConfigurationManager.AppSettings["inactivity_interval"]; 

将返回值。

for more check this

答案 1 :(得分:0)

app.config 中,将 appsetting 更改为

<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>

然后在代码隐藏C#中获取反向值:

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();

答案 2 :(得分:0)

在你的 app.config 中定义如下:

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

然后在您的 xaml 文件中引用命名空间:

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

并调用如下配置值:

Value="{Binding Source={x:Static p:Settings.Default}, Path=inactivity_interval}"