Please look at this code (creates a WPF grid with one row and one column):
Code: Select all
oGrid := Grid{}
oGrid:RowDefinitions:Add( RowDefinition{} )
oColDef := ColumnDefinition{}
oColDef:Width := GridLength{ 10 }
oGrid:ColumnDefinitions:Add( oColDef )
Possibility 1 - a VO programmer would subclass the ColumnDefinition class:
Code: Select all
class MyColumnDefinition inherit ColumnDefinition
constructor()
super()
return
constructor( oWidth as GridLength )
super()
self:Width := oWidth
return
constructor( nWidth as int )
super()
self:Width := GridLength{ nWidth }
return
end class
Code: Select all
oGrid := Grid{}
oGrid:RowDefinitions:Add( RowDefinition{} )
oGrid:ColumnDefinitions:Add( MyColumnDefinition{ 10 } )
oGrid:ColumnDefinitions:Add( MyColumnDefinition{ GridLength{ 10 } } )
Code: Select all
oGrid := Grid{}
oGrid:RowDefinitions:Add( RowDefinition{} )
oGrid:ColumnDefinitions:Add( ColumnDefinition{}{ Width := GridLength{ 10 } } )
And now possibility 3 - with extension methods in the Grid class:
Code: Select all
class GridExtensions
static method AddRow( self oGrid as Grid, nHeight as double ) as void
local oRowDefinition as RowDefinition
oRowDefinition := RowDefinition{}
oRowDefinition:Height := GridLength{ nHeight }
oGrid:RowDefinitions:Add( oRowDefinition )
return
static method AddRow( self oGrid as Grid, oHeight as GridLength ) as void
local oRowDefinition as RowDefinition
oRowDefinition := RowDefinition{}
oRowDefinition:Height := oHeight
oGrid:RowDefinitions:Add( oRowDefinition )
return
static method AddColumn( self oGrid as Grid, nWidth as double ) as void
local oColumnDefinition as ColumnDefinition
oColumnDefinition := ColumnDefinition{}
oColumnDefinition:Width := GridLength{ nWidth }
oGrid:ColumnDefinitions:Add( oColumnDefinition )
return
static method AddColumn( self oGrid as Grid, oWidth as GridLength ) as void
local oColumnDefinition as ColumnDefinition
oColumnDefinition := ColumnDefinition{}
oColumnDefinition:Width := oWidth
oGrid:ColumnDefinitions:Add( oColumnDefinition )
return
end class
and now how to use it:
Code: Select all
oGrid := Grid{}
oGrid:AddRow( 10 )
oGrid:AddRow( GridLength{ 1, GridUnitType.Star } )
oGrid:AddColumn( 10 )
oGrid:AddColumn( GridLength{ 1, GridUnitType.Pixel } )