public static void UpdateView(PropertyReference viewProperty, object value) { if (viewProperty == null || viewProperty.ContainingObject == null) return; var view = viewProperty.ContainingObject; string viewTypeName = view.GetType().FullName; switch (viewTypeName) { // TODO: Add cases here for specialized view types, as needed default: if (view is UITableView) { var tableView = (UITableView)view; var source = tableView.Source as DataBindableUITableViewSource; if (source != null) { var indexPath = source.GetIndexPath(value); tableView.SelectRow(indexPath, true, UITableViewScrollPosition.Middle); } } else { viewProperty.Value = value; } break; } }
public static void UpdateView(PropertyReference viewProperty, object value) { if (viewProperty == null || viewProperty.ContainingObject == null) return; if (!string.IsNullOrEmpty(viewProperty.PropertyOrFieldName)) { viewProperty.Value = value; return; } var view = viewProperty.ContainingObject; string viewTypeName = view.GetType().FullName; switch (viewTypeName) { // TODO: Add cases here for specialized view types, as needed default: if (view is UITableView) { var tableView = (UITableView)view; var source = tableView.Source as DataBindableUITableViewSource; if (source != null) { var indexPath = source.GetIndexPath(value); tableView.SelectRow(indexPath, true, UITableViewScrollPosition.Middle); } } else throw new NotImplementedException(string.Format("Unsupported view type {0} for UpdateView(). Add the type to either ViewDefaultPropertyOrFieldName or UpdateView()", viewTypeName)); break; } }
/// <summary> /// Override this method in a derived view class to change how a data-bound value is set for specific views /// </summary> /// <param name="viewProperty"></param> /// <param name="value"></param> public virtual void UpdateView(PropertyReference viewProperty, object value) { ViewDataBindings.UpdateView(viewProperty, value); }
public ItemDataBinding(PropertyReference viewProperty) { this.ViewProperty = viewProperty; }
public ItemDataBinding(FieldInfo objectFieldInfo, PropertyReference viewProperty) { this.ObjectFieldInfo = objectFieldInfo; this.ViewProperty = viewProperty; }
public static void UpdateView(PropertyReference viewProperty, object value) { if (viewProperty == null || viewProperty.ContainingObject == null) { return; } if (!string.IsNullOrEmpty(viewProperty.PropertyOrFieldName)) { viewProperty.Value = value; return; } var view = viewProperty.ContainingObject; string viewTypeName = view.GetType().FullName; switch (viewTypeName) { // TODO: Add cases here for specialized view types, as needed case "Android.Webkit.WebView": { var webView = (Android.Webkit.WebView)view; if (value is Uri) { string newUrl = value.ToString(); if (webView.Url != newUrl) { webView.LoadUrl(newUrl); } } else { webView.LoadData(value == null ? "" : value.ToString(), "text/html", null); } } break; default: if (view is TextView) { var textView = (TextView)view; string text = value == null ? "" : value.ToString(); if (textView.Text != text) { textView.Text = text; } } else if (view is AdapterView) { var adapterView = (AdapterView)view; var adapter = adapterView.GetAdapter() as IDataBindableListAdapter; if (adapter != null) { int position = adapter.GetItemPosition(value); if (adapterView is AbsListView) { var absListView = (AbsListView)adapterView; if (!absListView.IsItemChecked(position)) { absListView.SetItemChecked(position, true); } } else { if (adapterView.SelectedItemPosition != position) { adapterView.SetSelection(position); } } } } else { throw new NotImplementedException(string.Format("Unsupported view type {0} for UpdateView(). Add the type to either ViewDefaultPropertyOrFieldName or UpdateView()", viewTypeName)); } break; } }
public static void UpdateView(PropertyReference viewProperty, object value) { if (viewProperty == null || viewProperty.ContainingObject == null) return; if (!string.IsNullOrEmpty(viewProperty.PropertyOrFieldName)) { viewProperty.Value = value; return; } var view = viewProperty.ContainingObject; string viewTypeName = view.GetType().FullName; switch (viewTypeName) { // TODO: Add cases here for specialized view types, as needed case "Android.Webkit.WebView": { var webView = (Android.Webkit.WebView)view; if (value is Uri) { string newUrl = value.ToString(); if (webView.Url != newUrl) webView.LoadUrl(newUrl); } else { webView.LoadData(value == null ? "" : value.ToString(), "text/html", null); } } break; default: if (view is TextView) { var textView = (TextView)view; string text = value == null ? "" : value.ToString(); if (textView.Text != text) textView.Text = text; } else if (view is AdapterView) { var adapterView = (AdapterView)view; var adapter = adapterView.GetAdapter() as IDataBindableListAdapter; if (adapter != null) { int position = adapter.GetItemPosition(value); if (adapterView is AbsListView) { var absListView = (AbsListView)adapterView; if (!absListView.IsItemChecked(position)) { absListView.SetItemChecked(position, true); } } else { if (adapterView.SelectedItemPosition != position) adapterView.SetSelection(position); } } } else throw new NotImplementedException(string.Format("Unsupported view type {0} for UpdateView(). Add the type to either ViewDefaultPropertyOrFieldName or UpdateView()", viewTypeName)); break; } }