少し前に同じ問題が発生しました。 私が見つけることができる唯一の回避策は、スタイルをスキップし、独自のlistboxitemを作成することです。テキストだけが消えてしまうので、テキストを表示するためのラベルを追加しました。 それは偉大ではありませんが、私の場合にはたらきました
type
TMouseOverListBoxItem = class(TListBoxItem)
private
FBackGround: TRectangle;
FHoverAni: TColorAnimation;
FLabel: TLabel;
procedure BackgroundClicked(Sender: TObject);
protected
procedure DoTextChanged; override;
public
procedure AfterConstruction; override;
end;
procedure TMouseOverListBoxItem.AfterConstruction;
const
cStart = TAlphaColorRec.White;
cStop = TAlphaColorRec.Yellow;
begin
inherited;
// Create background
FBackGround := TRectangle.Create(Self);
FBackGround.Parent := Self;
FBackGround.Fill.Color := cStart;
FBackGround.Align := TAlignLayout.Contents;
FBackGround.HitTest := True;
FBackGround.Sides := [];
FBackGround.OnClick := BackgroundClicked;
// Create mouse over animation
FHoverAni := TColorAnimation.Create(FBackGround);
FHoverAni.Parent := FBackGround;
FHoverAni.Trigger := 'IsMouseOver=true';
FHoverAni.TriggerInverse := 'IsMouseOver=false';
FHoverAni.StartValue := cStart;
FHoverAni.StopValue := cStop;
FHoverAni.PropertyName := 'Fill.Color';
// Create label to show text. Background will hide original text
FLabel := TLabel.Create(FBackGround);
FLabel.Parent := FBackGround;
FLabel.Align := TAlignLayout.Client;
end;
procedure TMouseOverListBoxItem.BackgroundClicked(Sender: TObject);
begin
if Assigned(OnClick) then
OnClick(Self)
else if Assigned(ListBox.OnItemClick) then
ListBox.OnItemClick(ListBox, Self);
end;
procedure TMouseOverListBoxItem.DoTextChanged;
begin
inherited;
FLabel.Text := Self.Text;
end;