Hello
Main Problem: Change style of a grid at runtime over a contextmenu, save it and set in the case the application starts again.
Detailed:
- I have a style for each grid inside a resourceDictionary. This dictionary is added to Application.Current.Resources.MergedDictionaries.
- I have an attachable property for this kind of grid grid. If you set this to true, it taps the grid and add some additional functionalities (at the moment only enable/disable of columns over context menu)
- All the settings (order, filter,.... ) will be saved on each change into a config file, if the user adds another attachable property to the grid. (It taps the grid also and is listend to different kinds of chaning events). For each grid it has a section with specific setting inside this config file). At reloading of the application the properties are set to the grid again.
Now I have the requirement to change to foreground and the background color of the table content over this contextmenu at runtime. After a restart the selected colors should be like set before (I don't know the datacontext).
My approach was to create to add a colorpicker in the context menu, and in the case a new color is selected I create a new style with the new color like this:
<br />
localGridStyle = new Style(typeof(XY));<br />
<br />
_localGridStyle.Setters.Add(new Setter<br />
{<br />
Property = XY.BackgroundProperty,<br />
Value = _selectedBackground<br />
});<br />
this.grid.Resources.Add(typeof(XY), _localGridStyle);<br />
<br />
With this solution I can change the color and the grid overtakes the new set colors.
The problem is, how can I save this style and load again after restart?
Am I wrong complete?
Thanks