public
Form1()
{
InitializeComponent();
List<Item> dataItems =
new
List<Item>
{
new
Item(
"First"
,
"Some description"
, Properties.Resources.birthday),
new
Item(
"Second"
,
"Some description"
, Properties.Resources.birthday),
new
Item(
"Third"
,
"Some description"
, Properties.Resources.birthday),
new
Item(
"Fourth"
,
"Some description"
, Properties.Resources.birthday),
new
Item(
"Fifth"
,
"Some description"
, Properties.Resources.birthday),
new
Item(
"Sixth"
,
"Some description"
, Properties.Resources.birthday),
new
Item(
"Seventh"
,
"Some description"
, Properties.Resources.birthday),
};
this
.radGridView1.Columns.Add(
new
GridViewTextBoxColumn(
"Name"
));
this
.radGridView1.Columns.Add(
new
GridViewTextBoxColumn(
"Description"
));
this
.radGridView1.Columns.Add(
new
CustomImageColumn(
"Image"
));
this
.radGridView1.AutoGenerateColumns =
false
;
this
.radGridView1.DataSource = dataItems;
}
public
class
Item
{
public
string
Name {
get
;
set
; }
public
string
Description {
get
;
set
; }
public
Image Image {
get
;
set
; }
public
Item(
string
name,
string
description, Image image)
{
this
.Name = name;
this
.Description = description;
this
.Image = image;
}
}
public
class
ImageCell : GridDataCellElement
{
public
ImageCell(GridViewColumn column, GridRowElement row) :
base
(column, row)
{
}
private
StackLayoutElement stackElement;
private
LightVisualElement textElement;
private
LightVisualElement imageElement;
protected
override
void
CreateChildElements()
{
base
.CreateChildElements();
this
.stackElement =
new
StackLayoutElement();
this
.stackElement.StretchHorizontally =
true
;
this
.stackElement.StretchVertically =
true
;
this
.textElement =
new
LightVisualElement();
this
.imageElement =
new
LightVisualElement();
stackElement.Children.Add(textElement);
stackElement.Children.Add(imageElement);
this
.Children.Add(stackElement);
}
protected
override
void
SetContentCore(
object
value)
{
if
(
this
.Value !=
null
&&
this
.Value != DBNull.Value &&
this
.ColumnInfo.Name ==
"Image"
)
{
Item item =
this
.RowInfo.DataBoundItem
as
Item;
if
(item !=
null
)
{
this
.imageElement.Image = item.Image;
this
.imageElement.ImageLayout = ImageLayout.Zoom;
this
.textElement.Text = item.Description;
}
}
}
public
override
bool
IsCompatible(GridViewColumn data,
object
context)
{
return
data.Name ==
"Image"
&& context
is
GridDataRowElement;
}
protected
override
Type ThemeEffectiveType
{
get
{
return
typeof
(GridDataCellElement);
}
}
}
public
class
CustomImageColumn : GridViewDataColumn
{
public
CustomImageColumn(
string
fieldName) :
base
(fieldName)
{
}
public
override
Type GetCellType(GridViewRowInfo row)
{
if
(row
is
GridViewDataRowInfo)
{
return
typeof
(ImageCell);
}
return
base
.GetCellType(row);
}
}