diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/ExtensionsMethods.cs | 8 | ||||
| -rw-r--r-- | src/GraphicObjects/TemplatedGroup.cs | 13 | ||||
| -rw-r--r-- | src/Instantiator.cs | 3 |
3 files changed, 23 insertions, 1 deletions
diff --git a/src/ExtensionsMethods.cs b/src/ExtensionsMethods.cs index 6198dee6..6697be62 100644 --- a/src/ExtensionsMethods.cs +++ b/src/ExtensionsMethods.cs @@ -125,6 +125,14 @@ namespace Crow { return c == '\t' || c == '\r' || c == '\n' || char.IsWhiteSpace (c); } + public static object GetDefaultValue(this object obj) + { + Type t = obj.GetType (); + if (t.IsValueType) + return Activator.CreateInstance (t); + + return null; + } } } diff --git a/src/GraphicObjects/TemplatedGroup.cs b/src/GraphicObjects/TemplatedGroup.cs index c32b2c44..34d57727 100644 --- a/src/GraphicObjects/TemplatedGroup.cs +++ b/src/GraphicObjects/TemplatedGroup.cs @@ -148,7 +148,18 @@ namespace Crow } } [XmlIgnore]public virtual object SelectedItem{ - get { return data == null ? null : _selectedIndex < 0 ? null : data[_selectedIndex]; } + get { return data == null ? null : _selectedIndex < 0 ? data.GetDefaultValue() : data[_selectedIndex]; } + set { + if (data == null) { + SelectedIndex = -1; + return; + } + //TODO:double check if value type will be notified to binding sys + if (value == SelectedItem) + return; + + SelectedIndex = data.IndexOf (value); + } } [XmlIgnore]public bool HasItems { get { return Items.Count > 0; } diff --git a/src/Instantiator.cs b/src/Instantiator.cs index 297337ed..b3f070e7 100644 --- a/src/Instantiator.cs +++ b/src/Instantiator.cs @@ -890,6 +890,9 @@ namespace Crow.IML CompilerServices.emitConvert (il, piSource.PropertyType); + if (!piSource.CanWrite) + throw new Exception ("Source member of bindind is read only:" + piSource.ToString()); + il.Emit (OpCodes.Callvirt, piSource.GetSetMethod ()); il.MarkLabel (endMethod); |