最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

firemonkey - Delphi FMX & ListBox & Styles - Stack Overflow

programmeradmin0浏览0评论

I have a pretty simple app but I can't get it to work properly (as I assume).

Here is styles I have added:

object TStyleContainer
  object TLayout
    StyleName = 'CustomItem_edit'
    Align = Center
    Padding.Left = 3.000000000000000000
    Padding.Top = 3.000000000000000000
    Padding.Right = 3.000000000000000000
    Padding.Bottom = 3.000000000000000000
    Size.Width = 296.000000000000000000
    Size.Height = 64.000000000000000000
    Size.PlatformDefault = False
    Visible = False
    TabOrder = 2
    object TText
      StyleName = 'text'
      Align = Top
      HitTest = False
      Position.X = 3.000000000000000000
      Position.Y = 3.000000000000000000
      Size.Width = 290.000000000000000000
      Size.Height = 17.000000000000000000
      Size.PlatformDefault = False
      TextSettings.FontColor = xFF909090
      TextSettings.WordWrap = False
      TextSettings.HorzAlign = Leading
    end
    object TEdit
      StyleName = 'Edit1'
      Touch.InteractiveGestures = [LongTap, DoubleTap]
      Align = Top
      TabOrder = 0
      Position.X = 3.000000000000000000
      Position.Y = 20.000000000000000000
      Size.Width = 290.000000000000000000
      Size.Height = 21.000000000000000000
      Size.PlatformDefault = False
    end
  end
  object TLayout
    StyleName = 'CustomItem_list'
    Align = Center
    Padding.Left = 3.000000000000000000
    Padding.Top = 3.000000000000000000
    Padding.Right = 3.000000000000000000
    Padding.Bottom = 3.000000000000000000
    Size.Width = 296.000000000000000000
    Size.Height = 64.000000000000000000
    Size.PlatformDefault = False
    Visible = False
    TabOrder = 0
    object TText
      StyleName = 'text'
      Align = Top
      HitTest = False
      Position.X = 3.000000000000000000
      Position.Y = 3.000000000000000000
      Size.Width = 290.000000000000000000
      Size.Height = 17.000000000000000000
      Size.PlatformDefault = False
      TextSettings.FontColor = xFF909090
      TextSettings.WordWrap = False
      TextSettings.HorzAlign = Leading
    end
    object TComboBox
      StyleName = 'ComboBox1'
      Align = Top
      Position.X = 3.000000000000000000
      Position.Y = 20.000000000000000000
      Size.Width = 290.000000000000000000
      Size.Height = 22.000000000000000000
      Size.PlatformDefault = False
      TabOrder = 0
    end
  end
  object TLayout
    StyleName = 'CustomItem_label'
    Align = Center
    Padding.Left = 3.000000000000000000
    Padding.Top = 3.000000000000000000
    Padding.Right = 3.000000000000000000
    Padding.Bottom = 3.000000000000000000
    Size.Width = 296.000000000000000000
    Size.Height = 64.000000000000000000
    Size.PlatformDefault = False
    Visible = False
    TabOrder = 1
    object TText
      StyleName = 'text'
      Align = Top
      HitTest = False
      Position.X = 3.000000000000000000
      Position.Y = 3.000000000000000000
      Size.Width = 290.000000000000000000
      Size.Height = 17.000000000000000000
      Size.PlatformDefault = False
      Text = 'Text'
      TextSettings.FontColor = xFF909090
      TextSettings.WordWrap = False
      TextSettings.HorzAlign = Leading
    end
    object TLabel
      StyleName = 'Label1'
      Align = Top
      Position.X = 3.000000000000000000
      Position.Y = 20.000000000000000000
      Size.Width = 290.000000000000000000
      Size.Height = 17.000000000000000000
      Size.PlatformDefault = False
      TabOrder = 0
    end
  end
end

Nothing wrong here probably. I'm able to add items to ListBox:

item := TListBoxItem.Create(nil);
item.Parent := ListBox1;
item.StyleLookup := 'CustomItem_label';
item.StylesData['text'] := ;
item.StylesData['Label1.Text'] := ;

But how change height of individual item (ideally based of Label1 content / height)?

Have tried a lot of attemps, seems not working: not working

item.Height := 1000;

not working

item.StylesData['CustomItem_label.Height'] := 1000;

not working also

obj := StyleBook1.Style.FindStyleResource('CustomItem_label');
if (obj is TLayout) then begin
  TLayout(obj).Height := 1000;
end;

What can be a reason?

I have a pretty simple app but I can't get it to work properly (as I assume).

Here is styles I have added:

object TStyleContainer
  object TLayout
    StyleName = 'CustomItem_edit'
    Align = Center
    Padding.Left = 3.000000000000000000
    Padding.Top = 3.000000000000000000
    Padding.Right = 3.000000000000000000
    Padding.Bottom = 3.000000000000000000
    Size.Width = 296.000000000000000000
    Size.Height = 64.000000000000000000
    Size.PlatformDefault = False
    Visible = False
    TabOrder = 2
    object TText
      StyleName = 'text'
      Align = Top
      HitTest = False
      Position.X = 3.000000000000000000
      Position.Y = 3.000000000000000000
      Size.Width = 290.000000000000000000
      Size.Height = 17.000000000000000000
      Size.PlatformDefault = False
      TextSettings.FontColor = xFF909090
      TextSettings.WordWrap = False
      TextSettings.HorzAlign = Leading
    end
    object TEdit
      StyleName = 'Edit1'
      Touch.InteractiveGestures = [LongTap, DoubleTap]
      Align = Top
      TabOrder = 0
      Position.X = 3.000000000000000000
      Position.Y = 20.000000000000000000
      Size.Width = 290.000000000000000000
      Size.Height = 21.000000000000000000
      Size.PlatformDefault = False
    end
  end
  object TLayout
    StyleName = 'CustomItem_list'
    Align = Center
    Padding.Left = 3.000000000000000000
    Padding.Top = 3.000000000000000000
    Padding.Right = 3.000000000000000000
    Padding.Bottom = 3.000000000000000000
    Size.Width = 296.000000000000000000
    Size.Height = 64.000000000000000000
    Size.PlatformDefault = False
    Visible = False
    TabOrder = 0
    object TText
      StyleName = 'text'
      Align = Top
      HitTest = False
      Position.X = 3.000000000000000000
      Position.Y = 3.000000000000000000
      Size.Width = 290.000000000000000000
      Size.Height = 17.000000000000000000
      Size.PlatformDefault = False
      TextSettings.FontColor = xFF909090
      TextSettings.WordWrap = False
      TextSettings.HorzAlign = Leading
    end
    object TComboBox
      StyleName = 'ComboBox1'
      Align = Top
      Position.X = 3.000000000000000000
      Position.Y = 20.000000000000000000
      Size.Width = 290.000000000000000000
      Size.Height = 22.000000000000000000
      Size.PlatformDefault = False
      TabOrder = 0
    end
  end
  object TLayout
    StyleName = 'CustomItem_label'
    Align = Center
    Padding.Left = 3.000000000000000000
    Padding.Top = 3.000000000000000000
    Padding.Right = 3.000000000000000000
    Padding.Bottom = 3.000000000000000000
    Size.Width = 296.000000000000000000
    Size.Height = 64.000000000000000000
    Size.PlatformDefault = False
    Visible = False
    TabOrder = 1
    object TText
      StyleName = 'text'
      Align = Top
      HitTest = False
      Position.X = 3.000000000000000000
      Position.Y = 3.000000000000000000
      Size.Width = 290.000000000000000000
      Size.Height = 17.000000000000000000
      Size.PlatformDefault = False
      Text = 'Text'
      TextSettings.FontColor = xFF909090
      TextSettings.WordWrap = False
      TextSettings.HorzAlign = Leading
    end
    object TLabel
      StyleName = 'Label1'
      Align = Top
      Position.X = 3.000000000000000000
      Position.Y = 20.000000000000000000
      Size.Width = 290.000000000000000000
      Size.Height = 17.000000000000000000
      Size.PlatformDefault = False
      TabOrder = 0
    end
  end
end

Nothing wrong here probably. I'm able to add items to ListBox:

item := TListBoxItem.Create(nil);
item.Parent := ListBox1;
item.StyleLookup := 'CustomItem_label';
item.StylesData['text'] := ;
item.StylesData['Label1.Text'] := ;

But how change height of individual item (ideally based of Label1 content / height)?

Have tried a lot of attemps, seems not working: not working

item.Height := 1000;

not working

item.StylesData['CustomItem_label.Height'] := 1000;

not working also

obj := StyleBook1.Style.FindStyleResource('CustomItem_label');
if (obj is TLayout) then begin
  TLayout(obj).Height := 1000;
end;

What can be a reason?

Share Improve this question edited Apr 1 at 2:14 TylerH 21.1k78 gold badges79 silver badges114 bronze badges asked Mar 28 at 13:32 BxOOBxOO 335 bronze badges 1
  • 2 I'm not sufficiently familiar with customising list box items to figure this out from the little bits you've posted (which doesn't compile in any case). Please include a minimal reproducible example. – Philip J. Rayment Commented Mar 29 at 0:14
Add a comment  | 

1 Answer 1

Reset to default 1

I think you miss something, I made a little app to check (2 item style) I wrote this code

procedure TForm2.btnAddItemClick(Sender: TObject);
var newitem : TListBoxItem;
begin
  ListBox1.BeginUpdate;
  newItem:=TlistBoxItem.Create(listbox1);
  if Switch1.IsChecked then begin
                           newItem.StyleLookup:='itemstyledual';
                           newitem.Height:=(Random(2)+1)*40;
                       end
                       else begin
                         newItem.StyleLookup:='itemstylesolo';
                       end;
  newitem.ApplyStyleLookup;
  newItem.text:='Item '+Listbox1.Items.Count.ToString; 
// oops correct value should be Listbow1.Items.count+1 
  if Switch1.IsChecked then newitem.StylesData['extra']:='New item as '+newitem.Height.tostring+' Height';
  newitem.Parent:=Listbox1;
  listbox1.EndUpdate;
end; 

(2 first items at design time), Changing size works. To test : necessity of beginupdate/endupdate and newitem.applystylelookup even if, for me, it was a reflex (I don't work very often with customed Listbox)

发布评论

评论列表(0)

  1. 暂无评论