0

我有一个使用 GridView 作为视图的 ListView,并且列表中的每个项目都有一个带有 RadioButton 的 DataTemplate。我试图弄清楚如何检查第一个(或任何) RadioButton 并实际触发 Checked 事件。这是我的xml:

                <ListView.View>
                    <GridView>
                        <GridViewColumn Header="Selected">
                            <GridViewColumn.CellTemplate>
                                <DataTemplate>
                                    <RadioButton    Name="selectedFoo" 
                                                    Checked="selectedRadio_Checked"
                                                    IsChecked="True"

                                                    Tag="{Binding Id}"/>
                                </DataTemplate>
                            </GridViewColumn.CellTemplate>
                        </GridViewColumn>
                        <GridViewColumn Header="Id" DisplayMemberBinding="{Binding Id}"/>
                        <GridViewColumn Header="Name" DisplayMemberBinding="{Binding Name}"/>
                    </GridView>
                </ListView.View>
            </ListView>  
4

2 回答 2

0

我最终将处理程序附加到单选按钮加载事件并将其称为 Checked 处理程序。不是最好的解决方案,但它对我有用。

于 2012-05-11T14:28:51.570 回答
0
private void RadioListBox_SelectionChanged(object sender, RoutedEventArgs e)
{
    var button = sender as RadioButton;
    MessageBox.Show(button.Tag.ToString());
}


<ListView Margin="18,32,20,45" Name="lstVW" ItemsSource="{Binding}">
    <ListView.View>
        <GridView>
             <GridViewColumn Header="ID" DisplayMemberBinding="{Binding Id}" Width="50"/>
             <GridViewColumn Header="Drug Generic Name" DisplayMemberBinding="{Binding Name}" Width="700"/>
             <GridViewColumn Header="Status" DisplayMemberBinding="{Binding Status}" Width="100"/>
             <GridViewColumn Header="Status">
                 <GridViewColumn.CellTemplate>
                      <DataTemplate>
                           <StackPanel>
                                <RadioButton x:Name="rad" GroupName="optionsStatus" IsChecked="False" Tag="{Binding Id}" Background="WhiteSmoke" Height="30"  Click="RadioListBox_SelectionChanged"/>
                           </StackPanel>
                      </DataTemplate>
                 </GridViewColumn.CellTemplate>
            </GridViewColumn>
        </GridView>
    </ListView.View>
</ListView>
于 2014-07-19T17:56:19.603 回答