开发者

Where to set default values in a WPF C# app?

开发者 https://www.devze.com 2022-12-19 03:19 出处:网络
Where would I set default values that I want to use throughout a project and only define once? An example would be a default margin, or a color that I wan开发者_JS百科t to use in multiple places.

Where would I set default values that I want to use throughout a project and only define once?

An example would be a default margin, or a color that I wan开发者_JS百科t to use in multiple places.

In pure C, one way to do this would be with a "defaults.h" header file with "#define"s.


The simplest way to do this is to store them in the application's resource dictionary, either in markup (in the <Application.Resources> element in app.xaml) or by creating them in code at startup and adding them to the resource dictionary.

This allows you to do some pretty sophisticated stuff fairly easily, so long as you have a consistent application-wide naming convention for resource keys. For instance, it's easy to implement simple skinning in an application by building resource dictionaries in XAML files and then merging a specific dictionary into the application's dictionary at startup.


You can use the appsettings section of an app.config file. See here for more info.


You can do most of this with resources and templates, if you want common looks and styles throughout your app.

Edit: Based on your comment, looking at x:Static may be what you're after. Here's a SO question covering it. If that's still not quite it...try elaborating a bit more.

This is what I first read when playing around with WPF explaining it.

0

精彩评论

暂无评论...
验证码 换一张
取 消