更新时间:2023-12-06 15:14:40
谢谢 Mike.我不得不摆弄一下,但根据你的建议让它工作.我在stylecontainer中给我的textcellstyle添加了一个TRectangle,如下:
Thanks Mike. I had to fiddle around a bit, but got it to work based on your suggestion. I added a TRectangle to my textcellstyle in the stylecontainer, as follows:
textcellstyle : TLayout
background: TSubImage
rectangle1: TRectangle
rectanimation: TRectAnimation
在 TFinancialCell.ApplyStyle 中,我尝试了 FindStyleResource ('background'),但这总是返回 nil.我将其更改为 FindStyleResource ('rectangle1'),效果很好.这是因为它在对象检查器中查找相关的 StyleName 属性(对于矩形 1 显然默认为Rectangle1")?仍然没有完全看到树木的树木,我相信你可以告诉......
In TFinancialCell.ApplyStyle I tried FindStyleResource ('background'), but this always returned nil. I changed it to FindStyleResource ('rectangle1') and this worked great. Is this because it looks for the relevant StyleName property (which obviously defaults to 'Rectangle1' for rectangle 1) in the object inspector? Still not quite seeing the wood for the trees, as I'm sure you can tell...
工作代码:
Procedure TFinancialCell.ApplyStyle;
var
T : TFMXObject;
begin
inherited;
T:=FindStyleResource('Rectangle1');
If (T<>nil) and (T is TRectangle) then
begin
If TRectangle(T).Fill<>nil then
begin
If IsNegative then
begin
TRectangle(T).Fill.Color:=claRed;
Repaint;
end;
end;
end;
ApplyStyling;
end;
作为一个单独的练习,我还尝试将上面的代码放在 TFinancialCell.ApplyStyling 中,它也在那里工作,所以不确定哪个是更好的选择,为什么?
I also tried, as a separate exercise, to put the code above in TFinancialCell.ApplyStyling, and it also worked there, so not sure which is the better option, and why?
到目前为止我对这些风格的理解总结是(请根据需要更正/评论):
The summary of my understanding of these styles so far is (please correct/comment as necessary):