Collection in Widget Designer
I have been working over Sitefinity 4 since it has been launched. Few days back I ran into a situation where we needed to have collection (Dictionary, List etc) to be persistent in widget`s designer view, so that properties could be added, deleted existing options etc.
Here is a quick way to do that...
In the UserControl, we do like:
private
Dictionary<
string
,
string
> _TestProperty =
new
Dictionary<
string
,
string
>();
public
string
TestProperty
get
JavaScriptSerializer serializer =
new
JavaScriptSerializer();
if
(_TestProperty.Count == 0)
_TestProperty.Add(
"val1"
,
"abc"
);
_TestProperty.Add(
"val2"
,
"xyz"
);
return
serializer.Serialize(_TestProperty);
set
JavaScriptSerializer serializer =
new
JavaScriptSerializer();
_TestProperty = (Dictionary<
string
,
string
>) serializer.Deserialize(value,
typeof
(Dictionary<
string
,
string
>));
var
data =
this
._propertyEditor.get_control();
var
value = Sys.Serialization.JavaScriptSerializer.deserialize(data.TestProperty);