ItemsControl IsChecked 绑定路径内的 WPF RadioButton
我正在尝试将对象集合绑定到列表框,该列表框具有为单选按钮定义的项目模板。 在 IsChecked 属性的单选按钮中,我需要它绑定到的项目源对象的引用。
示例 Xmal:
<ListView ItemsSource="{Binding Path=Ports}">
<ListView.ItemTemplate>
<DataTemplate>
<RadioButton Grid.Row="0" IsChecked="{Binding Path=Port, Converter={StaticResource PortConverter}, ConverterParameter=ABC, UpdateSourceTrigger=PropertyChanged}">ABC</RadioButton>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
示例对象:
public class Port {
public string Name {get; set;}
}
视图模型:< /strong>
public IEnumerable< Port > Ports {get; set;}
需要一些指向相同的指针..
I am trying to bind a collection of object to Listbox which has a Item template defined for radio button.
In the radio button for IsChecked property i need the reference of the item source object that it is bind to..
Sample Xmal:
<ListView ItemsSource="{Binding Path=Ports}">
<ListView.ItemTemplate>
<DataTemplate>
<RadioButton Grid.Row="0" IsChecked="{Binding Path=Port, Converter={StaticResource PortConverter}, ConverterParameter=ABC, UpdateSourceTrigger=PropertyChanged}">ABC</RadioButton>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
Sample Object:
public class Port {
public string Name {get; set;}
}
View Model:
public IEnumerable< Port > Ports {get; set;}
Need some pointers to the same..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需从绑定中删除路径或将路径指定为点(.),它应该可以工作。我假设转换器中的代码采用 Port 类型的对象,并且根据某些条件,您将从那里返回 bool 值,因为 Port 是类的对象而不是 bool 值。
Just remove the path from your bindings or give path as dot(.), it should work. I am assuming that code in your converter takes an object of type Port and based on some conditions you are returning bool value from there since Port is an object of a class and not a bool value.