Silverlight ItemsControl - 更改 ItemTemplate
我有一个带有单选按钮列表的 ItemsControl - 在本例中,ItemTemplate 将包含一个绑定的单选按钮。 问题是,在某些情况下,我需要用复选框替换单选按钮,而不使用任何 C# 代码。这可能吗?我考虑使用 ValueConverter (C# 代码),但我不确定是否可行。
I have an ItemsControl with a list of radio buttons - in this case the ItemTemplate will contain a binded radio button.
The problem is that in some cases I need to replace the radio button with a check box without using any C# code. Is this possible? I thought at using a ValueConverter (C# code) but I don't know for sure if will work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在模板中放置一个单选按钮和一个复选框,然后在“Visible”属性中使用绑定表达式,以确保根据绑定的源对象只有其中一个可见。如果决定可见性的逻辑比源对象上的布尔值更复杂,请在绑定表达式中使用值转换器。
You could put both a radio button and a checkbox in the template, then use a binding expression in the "Visible" property that ensures only one of them is visible based on the source object being bound. If your logic to decide visibility is more complex than just a boolean on the source object, use a valueconverter in the binding expression.