Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.
This repository was archived by the owner on May 28, 2025. It is now read-only.

need to scrub the usage of applyTemplate in UIButton  #1671

@yiyang-msft

Description

@yiyang-msft

we have following pattern in UIButton. In order to retrieve temlateImage/Text, we invoke xamlButton applyTemplate and hope it force load all templated parts. But this pattern is not guaranteed to work until layout happen. Currently UIButton is working but might as well be lucky. We need come up with a solid pattern to make this approach more determinstic.

On the other hand hand, a separate pattern is being used in UITextField, which utilizes onLoadedEvent. But this requires caching value which isn't idea.

  • (void)_initUIButton {
    _xamlButton = rt_dynamic_cast([self xamlElement]);
    ...
    // Force-load the template, and get the TextBlock and Image for use in our proxies.
    [_xamlButton applyTemplate];
    ...
    WXCImage* templateImage = rt_dynamic_cast([WXCImage class], [_xamlButton getTemplateChild:@"buttonImage"]);
    WXCTextBlock* templateText = rt_dynamic_cast([WXCTextBlock class], [_xamlButton getTemplateChild:@"buttonText"]);

...
}

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions