我可以使用触发器在控件之间进行切换吗
我希望能够将我的列表视图“更改”为另一个控件。我正在考虑将控件的可见性设置为隐藏,然后单击按钮时更改可见性。我必须以编程方式执行此操作吗?或者我可以使用触发器吗?
I want to be able to "change" my listview into another control. I was thinking having the control's visibility set to hidden and when a button is clicked, change the visibility. Do I have to do this programatically? Or can I use a trigger?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用触发器来更改 ContentControl 的 Template 属性,这将包装您想要“可更改”的控件。检查一下:
将其添加到资源中:
使用另一个 ContentControl 对其进行测试:
我确信它可以进行优化,但应该会让您走上正轨。
You can use a trigger to change the Template property of a ContentControl, which will wrap the control you want to be "changeable". Check this:
Add this to Resources:
Test it using another ContentControl:
I'm sure it could be optimized, but should put you on the track.
您可以使用故事板和/或触发器来执行此操作,没问题。只需对要更改的元素的可见性属性进行动画处理即可。
You can use a Storyboard and/or trigger to do this, no problem. Just animate the Visibility properties on the elements you want to change.
要添加 Muad'Dib 的答案,另一种方法是将控件堆叠在一起,然后在触发器中来回淡出不透明度。您还可以使用 VSM 来执行此操作(创建 ListboxVisible 状态和 ListboxHidden 状态,或任何在语义上更有意义的名称)
To add to Muad'Dib's answer, another way you can do it is to stack the controls on top of each other, then fade the Opacity back and forth in the trigger. You can also do this with VSM (Create a ListboxVisible state and a ListboxHidden state, or whatever name makes more sense semantically)