Monotouch.Dialog从db生成并保留值

我有一个设置视图,我正在使用MT.D来构build我的用户界面。 我只是从数据库中读取元素来填充一个节中的元素。

我不知道该怎么做是访问每个元素的属性或值。 我想根据数据库中的值为每个项目设置不同背景颜色的元素。 我也希望能够得到选定的值,以便我可以在数据库中更新它。 下面是用MT.D做UI界面的代码的渲染。 我可以得到值显示,并像他们应该滑出…但是,造型或添加代表他们来处理我丢失的点击。

 List<StyledStringElement> clientTypes = SettingsController.GetClientTypes (); public SettingsiPhoneView () : base (new RootElement("Home"), true) { Root = new RootElement("Settings") { new Section ("Types") { new RootElement ("Types") { new Section ("Client Types") { from ct in clientTypes select (Element) ct } }, new StringElement ("Other Types") } 

以下是我如何处理它。 基本上你必须在foreach循环中创build元素,然后用你想要的任何东西来填充委托。 像这样:

 public static List<StyledStringElement> GetClientTypesAsElement () { List<ClientType> clientTypes = new List<ClientType> (); List<StyledStringElement> ctStringElements = new List<StyledStringElement> (); using (var db = new SQLite.SQLiteConnection(Database.db)) { var query = db.Table<ClientType> ().Where (ct => ct.IsActive == true && ct.Description != "Default"); foreach (ClientType ct in query) clientTypes.Add (ct); } foreach (ClientType ct in clientTypes) { // Build RGB values from the hex stored in the db (Hex example : #0E40BF) UIColor bgColor = UIColor.Clear.FromHexString(ct.Color, 1.0f); var localRef = ct; StyledStringElement element = new StyledStringElement(ct.Type, delegate { ClientTypeView.EditClientTypeView(localRef.Type, localRef.ClientTypeId); }); element.BackgroundColor = bgColor; ctStringElements.Add (element); } return ctStringElements; }