能否切换AdaptiveCard中Action的可见性?现有方案失效
能否切换Adaptive Card中Action的可见性?
Adaptive Card的Action元素无法直接通过Action.ToggleVisibility切换可见性,因为Action.ToggleVisibility的targetElements仅支持定位到卡片body区域内的元素,不能直接作用于actions数组中的Action项,这就是你当前方案失效的原因。
可行的实现方案
要实现类似的按钮切换效果,可以将需要控制的Action放入body内的Container组件中,通过切换Container的可见性间接控制Action的显示/隐藏。以下是修改后的示例代码:
{ "type": "AdaptiveCard", "version": "1.2", "body": [ { "type": "TextBlock", "text": "Press the buttons to toggle the button!", "wrap": true }, { "id": "showBtnContainer", "type": "Container", "actions": [ { "id": "btnShow", "type": "Action.ToggleVisibility", "title": "Show!", "targetElements": [ { "elementId": "showBtnContainer", "isVisible": false }, { "elementId": "hideBtnContainer", "isVisible": true } ] } ] }, { "id": "hideBtnContainer", "type": "Container", "isVisible": false, "actions": [ { "id": "btnHide", "type": "Action.ToggleVisibility", "title": "Hide!", "targetElements": [ { "elementId": "hideBtnContainer", "isVisible": false }, { "elementId": "showBtnContainer", "isVisible": true } ] } ] } ] }
方案说明
- 将原来的两个Action分别放入
showBtnContainer和hideBtnContainer两个Container中,这两个Container属于body区域的元素,支持被Action.ToggleVisibility定位。 - 初始状态下
hideBtnContainer设置为不可见,点击“Show!”按钮时隐藏自身容器、显示“Hide!”按钮所在的容器,反之亦然,实现按钮的切换显示效果。
内容的提问来源于stack exchange,提问作者user8555937
相关产品推荐
相关产品推荐

