You will add SearchBar to ActionBar and toggle it's visibility just like the example you linked.
(您将SearchBar添加到ActionBar并切换它的可见性,就像您链接的示例一样。)
XML
(XML格式)
<ActionBar title="Home">
<SearchBar visibility="{{ show, show ? 'visible' : 'hidden' }}"
clear="onToggleSearchBar">
</SearchBar>
<ActionItem visibility="{{ show, show ? 'hidden' : 'visible' }}"
text="Search" tap="onToggleSearchBar"></ActionItem>
</ActionBar>
TS
(TS)
export function onToggleSearchBar(args: EventData) {
(args.object as any).bindingContext.show = !(args.object as any).bindingContext.show;
}
ViewModel
(视图模型)
export class HomeViewModel extends Observable {
@ObservableProperty() show: boolean = false;
constructor() {
super();
}
}
Playground Sample
(游乐场样本)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…