What approach can be used for enabling users to define their own application preferences by setting personal values in some custom controls styles?
We can set them in XAML in design-time:
<UserControl.Resources>
<Style TargetType="{x:Type cc:MyControl}">
<Setter Property="SWidth" Value="20" />
...
<Setter Property="SBrush" Value="Blue" />
</Style>
</UserControl.Resources>
But how to edit these style values in runtime?
You'll want to bind the values in your style to some static class—for example, the application's default settings—that can be modified by whatever class defines what the values should be.
In the app below, I created a property called
FontSize
in theSettings.settings
file. I added the appropriate namespace in the XAML file and can now bind to it as I like:I bound the value directly to a
TextBox
but it goes without saying that some control mechanism, in a viewmodel for instance, is strongly recommended.Finally, if you want to save the settings, all you have to do is call the class's
Save
method, for example, in the event handler of the application'sExit
event: