列表框的图像如下:
Listbox with Dynamic column with check boxes and static radio buttons
我必须从列表框中选择所选项目,并为每个所选项目选择单选按钮
<ListBox Height="226" HorizontalAlignment="Left" Margin="404,339,0,0" Name="listBoxItems" VerticalAlignment="Top" Width="282" SelectionChanged="listBoxItems_SelectionChanged" SelectionMode="Multiple">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Margin="10,5,0,0">
<CheckBox Width="130" x:Name="chbPrescr" Content="{Binding}" IsChecked="{Binding RelativeSource={RelativeSource AncestorType={x:Type ListBoxItem}}, Path=IsSelected}">
<!--<TextBlock Text="{Binding}" Width="115"></TextBlock>-->
</CheckBox>
<RadioButton x:Name="rdOD" Width="40" Content ="OD" Checked="rdOD_Checked" />
<RadioButton x:Name="rdBD" Width="40" Content ="BD" Checked="rdBD_Checked"/>
<RadioButton x:Name="rdTDS" Width="40" Content ="TDS" Checked="rdTDS_Checked"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
在回发事件中,我正在选择列表项,但不是所选列表项的所选单选按钮
foreach (var items in listBoxItems.SelectedItems)
{
string a = items.ToString();
ItemCollection itemCollection = listBoxItems.Items;
object currentItem = itemCollection.CurrentItem;
}
我需要知道如何获得每种所选药物的类别。感谢
答案 0 :(得分:0)
您可以将IsChecked
的{{1}}属性绑定到数据类的source属性:
WPF + MVVM + RadioButton : Handle binding with single property
这是更好的解决方案。
最快的可能是在可视树中找到所选的RadioButtons
:
RadioButton