Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ItemsControl内的WPF单选按钮已检查绑定路径_Wpf_Radio Button_Itemscontrol - Fatal编程技术网

ItemsControl内的WPF单选按钮已检查绑定路径

ItemsControl内的WPF单选按钮已检查绑定路径,wpf,radio-button,itemscontrol,Wpf,Radio Button,Itemscontrol,我正在尝试将一个对象集合绑定到Listbox,它有一个为单选按钮定义的项模板。 在IsChecked属性的单选按钮中,我需要它绑定到的项源对象的引用 样本Xmal: <ListView ItemsSource="{Binding Path=Ports}"> <ListView.ItemTemplate> <DataTemplate> <RadioButton Grid.Row="0" IsChecked="{Binding Path=Por

我正在尝试将一个对象集合绑定到Listbox,它有一个为单选按钮定义的项模板。 在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;}

}
public IEnumerable< Port > Ports {get; set;}
查看模型:

<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;}

}
public IEnumerable< Port > Ports {get; set;}
public IEnumerablePort{get;set;}

需要一些指向相同..

的指针,只需从绑定中删除路径或将路径指定为点(.),就可以了。我假设转换器中的代码接受一个Port类型的对象,并且基于某些条件,您从那里返回bool值,因为Port是一个类的对象,而不是bool值

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

您需要提供更多详细信息。。。绑定对象看起来像什么?更新了模型和视图模型的更多详细信息。请忽略我以前的评论。。。其实绑定不是双向的;我被指定了UpdateSourceTrigger这一事实误导了。你的答案是正确的,+1;)