c# - In WPF how can I bind to settings in configSections in app.config? -


We have a small three-person WPF store (C # / WPF / .NET 4.0 CP), each of us right now There is also a relatively new WPF (less than a year of experience) There are so many internal, global constants in our application - things like background color, brush, pixel width, tooltip string - that we want to transfer to an app.config file.

At the same time, I have to be able to bind - in xaml - directly in these apps. Is it possible for config values?

I already know that you can reach the mean key / value pairs defined here:

  & lt; App settings and gt; & Lt; Add key = "TextBlockHeight" value = "50" /> & Lt; / AppSettings & gt;   

by adding a namespace to your xaml

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

and then into that reference Body

  & lt; TextBlock Height = "{Binding Source = {x: Static P: Settings. Default}, Path = Text BlockHite}" />   

To date, I do not know about any of this capability, but it makes sense to me, on what I have not got anything, it is a clear statement that what this reference will give

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

Who and what properties generate the object Has been doing? And why bindings reference is reference. Default ? What's the default? Can there be other attributes on the setting object?

Above it and beyond, our application is complicated enough that I want to do two things:

1. Use the config section to isolate our configurable values ​​according to our internal module

It will look like this:

  & lt; ConfigSections & gt; & Lt; Section group name = "Qst2ConfigGroup" & gt; & Lt; Section name = "Qst2Settings" type = "WinWam6.Qst2ConfigSection, WW6-WPF" / & gt; & Lt; / SectionGroup & gt; & Lt; / ConfigSections & gt; ... & lt; Allow QT2 settings to load 2 async = "true" permission. Type 2 parallel = "true" allowed 2 parallowload = "true" allow MultiThread = "true" ShowNodeData = "true" ShowAllFailNotes = "true" ShowAllRules = "true" ShowAllValues ​​= "True" TwipsPerPixelX = "15.0" TwipSpeakYquai = "15.0" />   

2. Config DLLs out of the main app and be able to pass in the DLL below. DLL will implement some reporting features and we know from the previous experience that we want the runtime value of those configuration parameters.

I'm less worried with # 2 now, and more interested in # 1. There is a way to say something like this:

  & lt; Checkbox Ishakhek = "{Binding Source = {x: Static Page: Settings. Qst2ConfigGroup}, Path = Qst2Settings.LoadQst2Aynync}" />   

And simply I have dabled with this and actually have a support class for WinWam6.Qst2ConfigSection. I'm not sure I'm going down here right Avenue.

When you create an application or library, you can see the "Properties" folder. Inside this folder, Resouces.resx and Settings.settings will be. When you refer to xmlns: p = "clr-namespace: SampleApp.Properties" , then it actually gives the content to this folder in Settings.Designer.cs, you see "SampleApp. Properties.Settings can define with "a fixed asset here" with " default ". You want to know about default .

So, the settings that you are actually using are Defined in settings, but not in the app. Config If you want to use the key / value pair in App.Config, you must use the System.configuration.ConfigurationSettings.AppSettings . But these are all key / value pairs, so you can not use it easily in XAML. You may have to add a typewriter for this.

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -