0

我正在使用 listview 包含 gridview 来绑定数据。我想在按钮单击事件上找到复选框控件(即 chkUser)。(即btnUserId点击事件)

我怎样才能实现它?如果这里有任何其他替代解决方案,请告诉我。

我的代码:

<ListView Name="listUsers" SelectionMode="Single" Height="200" SelectionChanged="listUsers_SelectionChanged">
    <ListView.View>
        <GridView AllowsColumnReorder="true">
            <GridViewColumn Header="User Id" >
                <GridViewColumn.CellTemplate>
                    <DataTemplate>
                        <Button Name="btnUserId" Cursor="Hand"  Tag="{Binding Path=UserId }" Click="btnUserId_Click" Content="{Binding Path=UserId }" Style="{StaticResource LinkButton}"></Button>
                    </DataTemplate>
                </GridViewColumn.CellTemplate>
            </GridViewColumn>
            <GridViewColumn Header="Name" DisplayMemberBinding="{ Binding Path=UserName }"></GridViewColumn>
            <GridViewColumn Header="Email Id" DisplayMemberBinding="{ Binding Path=Email }"></GridViewColumn>
            <GridViewColumn Header="Mobile" DisplayMemberBinding="{ Binding Path=Mobile }"></GridViewColumn>
            <GridViewColumn Header="User Type" >
                <GridViewColumn.CellTemplate>
                    <DataTemplate>
                        <Label Name="lblUserType">User Type</Label>
                    </DataTemplate>
                </GridViewColumn.CellTemplate>
            </GridViewColumn>
            <GridViewColumn Header="Active" >
                <GridViewColumn.CellTemplate>
                    <DataTemplate>
                        <CheckBox Name="chkUser" Width="120" Content="{Binding Path=deleted }"></CheckBox>
                    </DataTemplate>
                </GridViewColumn.CellTemplate>
            </GridViewColumn>
            <GridViewColumn Header="Update" >
                <GridViewColumn.CellTemplate>
                    <DataTemplate>
                        <Button Height="23" Name="button1" Tag="{Binding Path=UserId }" CommandParameter="{ Binding Path=UserId }" Click="button1_Click" Width="75">Button</Button>
                    </DataTemplate>
                </GridViewColumn.CellTemplate>
            </GridViewColumn>
        </GridView>
    </ListView.View>
</ListView>
4

1 回答 1

1

您应该能够使用 FindName 通过其名称来定位 ctrl。在上述情况下,它将是

listUsers.FindName("chkUser");

干杯

于 2013-01-31T11:58:20.390 回答