TableView background image

Hi TMS,


is there a way to place a background image in a table view, that is visible when no items are in the list and any item created will be placed over the image, blocking partly the view ??

Thanks in advance,
Helge

Hi, 


You can accomplish this with the following code:

  TMSFMXTableView1.NeedStyleLookup;
  TMSFMXTableView1.ApplyStyleLookup;
  (TMSFMXTableView1.GetListBackGround as TRectangle).Fill.Bitmap.WrapMode := TWrapMode.TileStretch;
  (TMSFMXTableView1.GetListBackGround as TRectangle).Fill.Bitmap.Bitmap.LoadFromFile('MyImage.png');
  (TMSFMXTableView1.GetListBackGround as TRectangle).Fill.Kind := TBrushKind.Bitmap;

TMSFMXTableView1.GetListBackGround returns nil

IN the style editor I also can't find the 'itembackground' style resource mentioned in the code, even if i put a new tableview on a form

Can you execute the code in the OnApplyStyleLookup event:


procedure TForm1.TMSFMXTableView1ApplyStyleLookup(Sender: TObject);
begin
  (TMSFMXTableView1.GetListBackGround as TRectangle).Fill.Bitmap.WrapMode := TWrapMode.TileStretch;
  (TMSFMXTableView1.GetListBackGround as TRectangle).Fill.Bitmap.Bitmap.LoadFromFile('MyImage.png');
  (TMSFMXTableView1.GetListBackGround as TRectangle).Fill.Kind := TBrushKind.Bitmap;
end;

The second one works, thanks a lot, Not in a thousand years I'd have the idea to do it that way ;)

Maybe it could be just a property ? Since the tableview can be used for chats like whatsapp and they support background images, maybe it wouldn't be a bad idea to have a less hidden way to achieve it ;)

Thanks again, 
Helge
We will added this on our feature request list.
The list background is only available if the style is loaded, this is why the GetListBackGround returns nil. The following code should make the list background available and force the style to be loaded.

 TMSFMXTableView1.NeedStyleLookup;
 TMSFMXTableView1.ApplyStyleLookup;

I placed that code but the list still was nil, in your first example you hade those 2 lines, too.

Hi, 


We have placed the code in the formcreate, did you use another place to execute the code (button click for example)?

Yes, I have no FormCreate as the TableView is placed on a TFrame, after create I call an Init procedure, where the code is executed

After further investigation it seems the frame initialization is different from the form initialization and the style is not directly loaded. We will investigate if we can improve this behavior, but you can use the workaround as suggested.

I'm already using it and it works great, thanks again, guys :)