问题描述:

I used IsolatedStorage to save window position ( Windows.Top and Window.Left) of my WPF application using this kind of approach.

Now I want to save, always in the IsolatedStorage, a Brush. It can be a SolidColorBrush or a LinearGradientBrush based on user choice.

For a SolidColorBrush I can just save the 3 values of RGB Color, but how treat a LinearGradientBrush?

I think it's possible to serialize a Brush object, but I'm really stuck.

Now my question is: It's possible to save Brush in an IsolatedStorage?

I chose to use IsolatedStorage because my application needs to be a single exe, without installation ( it's distribuited to client with a custom software distribution program), usually executed from the desktop. The application give to user with right credentials informations about Active Directory Users.

Edit:

Any other solution provided to save user customizations is welcome!

网友答案:

Brush and other semi-native drawing object are not serializable. So you will not be able to store them in any persistent or out-of-process storage.

Since it looks like you have limited set of objects it should be easy to get all properties and store them by hand. Creating serializable helper/wrapper classes that can be stored in a Stream and act as factory for corresponding type may be an option.

网友答案:

First, I wouldn't use IsolatedStorage, but user-scoped settings to store this kind of information. Second, if you can't serialize the brush, you could save whatever information the user enters in order to choose or create the brush: if they just choose a brush from existing resources, save those resources' keys, if they can enter rgb values to choose a color, save the rgb values, and whatever they do to define a LinearGradientBrush, just save their input values.

相关阅读:
Top