我不确定是否可能-但对我来说似乎应该是。本质上,我想在更改 StyleLookup 时触发所有组件刷新它们的样式。
我有一个 FMXComponent,它是一个名为BaseStyleLabel
. 组件的StyleName
属性是'BaseStyle'。它本身从样式资源中查找其样式,因此其StyleLookup
属性设置为'BaseStyle1'。我也有'BaseStyle2','BaseStyle3' ...
我有一个被调用的依赖 Tlabel,MyTextLabel
它的StyleLookup
属性设置为BaseStyle
,即 StyleName BaseStyleLabel
。
这一切似乎都很好。我看到它MyTextLabel
继承了MyBaseStyle
' BaseStyle1'的样式。
当我执行这行代码时
BaseStyleLabel.StyleLookup := 'BaseStyle2';
Self.repaint; // repaint whole form
我希望会BaseStyleLabel
更改为“BaseStyle2”(确实如此)。然而,MyTextLabel
也应该改变风格,然后看起来像'BaseStyle2',但它没有:它仍然是BaseStyle1
;
限定符是 BaseLabel 和 MyTextLabel 都来自样式资源。它们实际上不是在表单上创建的组件,它们是由样式创建的。
所以我的问题是这个。
- 这种方法有效吗?
- 是否有标准方法,例如使用可以更新的样式对象?
- 我只是没有刷新正确的东西吗?
- 使用了错误的刷新方法,可能是ApplyStyle?
...编辑....下面是请求的示例...
unit Unit1;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Graphics, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.StdCtrls;
type
TForm1 = class(TForm)
MyTextLabel: TLabel;
StyleBook1: TStyleBook;
BaseStyleLabel: TLabel;
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.fmx}
procedure TForm1.FormCreate(Sender: TObject);
begin
// Set up BaseStyleLabel as a Style Source
BaseStyleLabel.StyleName := 'BaseStyle';
// Set its Style to a Resources Style "STYLE ONE"
BaseStyleLabel.StyleLookup := 'BaseStyle1';
// Point MyTextLabel to whatever "BaseStyleLabel" is styled as...
MyTextLabel.StyleLookup := 'BaseStyle'; // also says "STYLE ONE"
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
//Change BaseStyle Label to "STYLE TWO" (works OK)
BaseStyleLabel.StyleLookup := 'BaseStyle2';
// ... BUT MyTextLabel stays as "STYLE ONE"
// can I repaint???
// Auto Cascade?
// What about when Other TLabels are part of a different component style?
end;
end.
使用以下样式文件
object TStyleContainer
object TLabel
StyleName = 'BaseStyle1'
DesignVisible = False
Height = 17.000000000000000000
Position.X = 521.000000000000000000
Position.Y = 432.000000000000000000
Text = 'STYLE ONE'
Width = 120.000000000000000000
end
object TLabel
StyleName = 'BaseStyle2'
DesignVisible = False
Height = 17.000000000000000000
Position.X = 521.000000000000000000
Position.Y = 432.000000000000000000
Text = 'STYLE TWO'
Width = 120.000000000000000000
end
object TLabel
StyleName = 'BaseStyle3'
Height = 17.000000000000000000
Position.X = 521.000000000000000000
Position.Y = 432.000000000000000000
Text = 'STYLE 3'
Width = 120.000000000000000000
end
end