Silverlight 条件复选框/单选按钮
想象一下,我有一个名称列表,每个名称都与一个值配对(“C”代表复选框,“R”代表单选按钮)。
我可以组合一个模板来根据给定值显示正确的控件吗?
例如,如果我有“Name0,C”,我想显示一个标记为 Name0 的复选框。 如果我有“Name1,R”,我想显示一个标记为 Name1 的单选按钮。
有什么想法吗?或者仅使用模板就可以做到这一点?也许我需要在代码隐藏中做出决定?
Imagine I had a list of names, each paired with a value ("C" for CheckBox or "R" for RadioButton).
Can I put together a template to display the correct control based on the given value?
For instance if I have "Name0, C" I'd like to display a CheckBox labeled Name0.
If I have "Name1, R" I'd like to display a RadioButton labeled Name1.
Any ideas? Or is this even possible using only a template? Perhaps I would need to make the determination in the code-behind?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许您可以使用同时具有复选框和单选按钮的数据模板。然后,您可以为
ValueToVisability
创建一个类型转换器来显示一个并隐藏另一个。Perhaps you could use a data template that has both a Checkbox and RadioButton. You could then create a type converter for
ValueToVisability
to display one and hide the other.