Reputation: 919
I want to make a quite complex interface where one ListBox is in another one. First, all elements of ListBox1 get a style "CustomItem" from Style Designer in Firemonkey:
Item := TListBoxItem.Create(nil);
Item.Parent := ListBox1;
Item.StyleLookup := 'CustomItem';
Then, there is another ListBox ("ListBox2") in the style "CustomItem".
How can I access "StyleLookup" property of this ListBox2?
Item.StylesData['ListBox2'].StyleLookup := 'CustomItem2'; //this does not work.
Do you know if Firemonkey supports that?
Thank you.
Upvotes: 2
Views: 3180
Reputation: 4211
I'm not familiar with the usage of StylesData, but this can be done with FindStyleResource in the OnApplyStyleLookup event handler.
procedure TForm1.ApplyStyleLookupEvent(Sender: TObject);
var O: TFMXObject;
begin
O := (Sender as TFMXObject).FindStyleResource('ListBox2');
if O is TStyledControl then
TStyledControl(O).StyleLookup := 'CustomItem2';
end;
You can also put this in your ApplyStyle procedure if you have a custom TListBoxItem object.
Upvotes: 1
Reputation: 2977
You misunderstood how the TListBox component works and how the StyleLookup property is involved. The only control that the TListBox can host is a TListBoxItem or a descendant of that control.
the CustomItem
that you refer to is just a name of the Style Object which is apart of a custom
FMX style included in the Delphi Firemonkey CustomListBox sample.
You can assign a style object to a specific list box item by providing it's name to the StyleLookup
property.
The item will then visually behave as instructed by that Style Object.
What you really are looking for is the FMX.TTreeView component. You can make it behave exactly like the TListBox with the added bonus of Items being able to host child items. I suggest you take a good look at the provided Firemonkey sample.
Upvotes: 2