WinForms databinding seems to be not so powerful as WPFs databinding, but simple solutions are possible also here. Please look at this peace of code:
Code: Select all
using System.Windows.Forms
using System.ComponentModel
class BaseView inherit Form
constructor()
return
method Use( oViewModel as INotifyPropertyChanged ) as void
local oControls as System.Windows.Forms.Control.ControlCollection
local oTextBox as TextBox
oControls := self:Controls
foreach oControl as Control in oControls
do case
case oControl is TextBox
oTextBox := ( TextBox ) oControl
oTextBox:DataBindings:Add( "Text", oViewModel, oTextBox:Name )
endcase
next
return
end class
Code: Select all
oSampleView := SampleView{}
oSampleView:Use( SampleViewModel{} )
Application.Run( oSampleView )
As always you can find a complete working sample application in XIDE export format attached to this message.
Wolfgang