public void Connect(Gtk.Widget widget, Object source, IBindingTarget target) { if (source == null) { mSource = BindingEngine.GetViewModel(widget); if (mSource == null) { Console.WriteLine("Binding.Connect: ViewModel not set for this widget"); return; } } else { mSource = source; } mTarget = target; var propertyChanged = mSource as IPropertyChanged; if (propertyChanged != null) { propertyChanged.PropertyChanged += (object sender, PropertyChangedEventArgs e) => mTarget.Update(this, GetSourceValue()); } }
public void Apply(Gtk.Widget widget) { Gtk.Entry entry = widget as Gtk.Entry; if (entry == null) { Console.WriteLine("EntryTemplate.Apply: Invalid widget type for this template"); return; } if (mTextBinding != null) { var bindingTarget = new EntryBindingTarget(entry); Binding binding = BindingEngine.GetOrCreateBinding(widget, null, bindingTarget, mTextBinding); bindingTarget.Update(binding, binding.GetSourceValue()); } }
private static void ValuePropertyDataFunc(Gtk.TreeViewColumn column, Gtk.CellRenderer cell, Gtk.TreeModel model, Gtk.TreeIter iter) { var treeView = (Gtk.TreeView)column.TreeView; var info = Templating.GetTemplate(treeView) as TreeViewTemplate; var textCell = (cell as Gtk.CellRendererText); textCell.Text = string.Empty; var value = model.GetValue(iter, 0); if (value == null) { return; } foreach (var rowTemplate in info.RowTemplates) { if (value.GetType() == rowTemplate.TargetType) { //Here we have a value, which is the source for Binding, and a BindingInfo that is given by rowTemplate.ColumnBindings[column.Title] . //The instance of the BindingInfo is shared among all values (rows), since it was defined once in the rowTemplate. BindingInfo bindingInfo = null; if (!rowTemplate.ColumnBindings.TryGetValue(column.Title, out bindingInfo)) { return; } //The actual binding, on the other hand, is specific to the current (row,column) pair. Binding binding = BindingEngine.GetOrCreateBinding(treeView, value, new TreeViewIterBindingTarget(treeView, iter, column), bindingInfo); var propValue = binding.GetSourceValue(); textCell.Text = propValue == null ? String.Empty : propValue.ToString(); return; } } }