Using MVVM, you can assign also numeric or date values, but the way back is not in your control.
My first try was to implement a :Value property and detect the type of the value automatically:
Code: Select all
property _value as object
get
return _oValue
end get
set
_oValue := value
self:_SetType( oValue )
end set
end property
private method _SetType( oValue as object ) as void
_oValueType := oValue:GetType()
self:Text := oValue:ToString()
return
Code: Select all
private method __Update() as void
local oValue as object
local oInfo as System.Reflection.MethodInfo
local lSuccess as logic
local aParameters as object[]
local cTextValue as string
local aTypes as System.Type[]
aTypes := <System.Type>{ TypeOf( string ), ( ( System.Type ) _oValueType ):MakeByRefType() }
oInfo := _oValueType:GetMethod( "TryParse", aTypes )
cTextValue := self:Text
oValue := null
aParameters := <object>{ cTextValue, oValue }
lSuccess := ( logic ) oInfo:Invoke( null, aParameters )
if lSuccess
oValue := aParameters[__ARRAYBASE__+1]
self:Value := oValue
_cTextValue := cTextValue
else
self:Text := _cTextValue
endif
return
But the shown solution works well if you are using WPF without MVVM - in the next days I will show a IMHO better solution based on a generic TypeConverter.
Wolfgang