Best way to bind WPF properties to ApplicationSettings in C#?

后端 未结 7 707
野的像风
野的像风 2020-12-07 15:40

What is the best way to bind WPF properties to ApplicationSettings in C#? Is there an automatic way like in a Windows Forms Application? Similar to this question, how (and

7条回答
  •  -上瘾入骨i
    2020-12-07 16:31

    The easiest way would be to bind to an object that exposes your application settings as properties or to include that object as a StaticResource and bind to that.

    Another direction you could take is creation your own Markup Extension so you can simply use PropertyName="{ApplicationSetting SomeSettingName}". To create a custom markup extension you need to inherit MarkupExtension and decorate the class with a MarkupExtensionReturnType attribute. John Bowen has a post on creating a custom MarkupExtension that might make the process a little clearer.

提交回复
热议问题