For example, I have a custom control map, which has four dependency attributes used to control map scaling and allows the user app. config to modify the default value,
ThereforeProgramUse settings. settings.
1. C #CodeMethod
Binding binding = New Binding ( " Mapzoom " );
Binding. Source = Properties. settings. default;
Map. setbinding (Map. zoomproperty, binding );
Binding = New Binding ( " Mapzoommax " );
Binding. Source = Properties. settings. default;
Map. setbinding (Map. zoommaxproperty, binding );
Binding = New Binding ( " Mapzoommin " );
Binding. Source = Properties. settings. default;
Map. setbinding (Map. zoomminproperty, binding );
Binding = New Binding ( " Mapzoomspan " );
Binding. Source = Properties. settings. default;
Map. setbinding (Map. zoomspanproperty, binding );
From:Http://greatverve.cnblogs.com/archive/2011/06/27/wpf-Properties-Settings.html
2. XAML method (recommended)
Xmlns: Properties = "CLR-namespace: application1.properties" < Views: Map Dockpanel. Dock = "TOP"
Zoom =" {Binding Path = mapzoom, source = {X: static properties: settings. Default }} "
Zoommax =" {Binding Path = mapzoommax, source = {X: static properties: settings. Default }} "
Zoommin =" {Binding Path = mapzoommin, source = {X: static properties: settings. Default }} "
Zoomspan =" {Binding Path = mapzoomspan, source = {X: static properties: settings. Default }} " /> 3. In the XAML modeObjectdataproviderXmlns: Local = "CLR-namespace: application1"
<Objectdataprovider X: Key = "odpsettings" objecttype = "{X: type local: properties. settings}"> </objectdataprovider>
< Views: Map Dockpanel. Dock = "TOP"
Zoom =" {Binding Path = default. mapzoom, source = {staticresource odpsettings }} "
Zoommax =" {Binding Path = default. mapzoommax, source = {staticresource odpsettings }} "
Zoommin =" {Binding Path = default. mapzoommin, source = {staticresource odpsettings }} "
Zoomspan =" {Binding Path = default. mapzoomspan, source = {staticresource odpsettings }} " />