ItemsControl IsChecked 绑定路径内的 WPF RadioButton

发布于 2024-12-11 10:39:51 字数 790 浏览 0 评论 0原文

我正在尝试将对象集合绑定到列表框,该列表框具有为单选按钮定义的项目模板。 在 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技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

伤痕我心 2024-12-18 10:39:51

只需从绑定中删除路径或将路径指定为点(.),它应该可以工作。我假设转换器中的代码采用 Port 类型的对象,并且根据某些条件,您将从那里返回 bool 值,因为 Port 是类的对象而不是 bool 值。

<RadioButton Grid.Row="0" IsChecked="{Binding Path=., Converter={StaticResource PortConverter}, ConverterParameter=ABC, UpdateSourceTrigger=PropertyChanged}">ABC</RadioButton>

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.

<RadioButton Grid.Row="0" IsChecked="{Binding Path=., Converter={StaticResource PortConverter}, ConverterParameter=ABC, UpdateSourceTrigger=PropertyChanged}">ABC</RadioButton>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文