// 代码与原生侧栏都操作真实 Page 对象;activate/close/open 改变展示关系,业务对象可继续被全局引用保留。 // 三个页面共存于同一 VM,最后 first.activate 选择初始展示页。 // 当前宿主通过侧栏管理页面;Page 的代码接口保持同一业务身份。 // 创建持有计数器与按钮的页面;切到其他页不等于销毁 count。 first = Page() first.title = "共享计数" count = ui.state(0) increment = Button("加一") connection = increment.on("click", count.increment) first.render(Column(24,16,TextBlock("切换页面后,计数对象继续存在"),ui.textOf(count,"value"),increment)) // 另一页演示 Page 生命周期与快捷键;界面提示是示例文案,实际导航位于当前宿主侧栏。 second = Page() second.title = "另一个页面" second.render(Column(24,16,TextBlock("点击上方 Tab 切换;× 关闭页面"),TextBlock("Ctrl+Tab 切换,Cmd/Ctrl+W 关闭;代码可调用 first.open() 重开"))) // 独立内容页面仍用同一个运行时的原生类型和资源注册表。 third = Page() third.title = "窗口与布局" third.render(Column(24,16,TextBlock("每个 Tab 都是同一个 VM 中的 Page 对象"),RectBlock(240,80,8,"#237A45"))) // 重新激活第一页面,原生侧栏和源查询可观察相同 active 状态。 first.activate() ui.window().setTitle("Endor Pages")