From 6f3b4f69ff27623bd94454514e024adf5893503b Mon Sep 17 00:00:00 2001 From: jpbruyere Date: Thu, 10 Sep 2015 23:49:46 +0200 Subject: [PATCH] Minimal requirements to have selected Item from ListBox --- src/GraphicObjects/GraphicObject.cs | 1 + src/GraphicObjects/ListBox.cs | 18 ++++++++++-------- src/Interface.cs | 1 + 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs index d74442d7..03d43da0 100644 --- a/src/GraphicObjects/GraphicObject.cs +++ b/src/GraphicObjects/GraphicObject.cs @@ -298,6 +298,7 @@ namespace go get { return _minimumSize; } set { _minimumSize = value; } } + [XmlIgnore]public object DataSource; #endregion /// diff --git a/src/GraphicObjects/ListBox.cs b/src/GraphicObjects/ListBox.cs index 117dd626..ee068ac5 100644 --- a/src/GraphicObjects/ListBox.cs +++ b/src/GraphicObjects/ListBox.cs @@ -43,7 +43,7 @@ namespace go } #endregion - ICollection data; + IList data; int _selectedIndex; string _itemTemplate; @@ -56,9 +56,11 @@ namespace go get { return _selectedIndex; } set { _selectedIndex = value; } } - + public object SelectedItem{ + get { return data[_selectedIndex]; } + } [XmlAttributeAttribute][DefaultValue(null)] - public ICollection Data { + public IList Data { get { return data; } @@ -70,16 +72,16 @@ namespace go return; foreach (var item in data) { GraphicObject g = Interface.Load (ItemTemplate, item); - //GraphicObject g = Interface.Load ("#go.Templates.Listbox.goml", item); -// g.Tag = item; -// g.MouseClick += (object sender, OpenTK.Input.MouseButtonEventArgs e) => { -// -// }; + g.MouseClick += itemClick; _list.addChild(g); } } } + void itemClick(object sender, OpenTK.Input.MouseButtonEventArgs e){ + NotifyValueChanged ("SelectedItem", (sender as GraphicObject).DataSource); + //Debug.WriteLine ((sender as GraphicObject).DataSource); + } } } diff --git a/src/Interface.cs b/src/Interface.cs index 1812217b..69e8d9d0 100644 --- a/src/Interface.cs +++ b/src/Interface.cs @@ -123,6 +123,7 @@ namespace go XmlSerializer xs = new XmlSerializer(type); result = (GraphicObject)xs.Deserialize(stream); + result.DataSource = hostClass; if (hostClass == null) { GOMLResolutionStack.Pop (); -- 2.47.3