【发布时间】:2016-05-31 12:46:24
【问题描述】:
你好!我在使用 Listview 时遇到问题
这似乎是一个已知问题,我找到了很多具有解决方案的主题,但仅适用于 Java/Android 应用程序,您可以在此处看到:
checkbox unchecked when i scroll listview in android 我没有设法了解解决方案的工作原理,以便将其翻译成 Visual Basic,所以我在这里,希望得到一些帮助! ---------------------- 这是我的程序的工作原理 ---------------- ------ 我有一个包含一定数量列的 DataGrid。在我的 Listview 中,每个复选框都链接到一个列,以便在选中/取消选中复选框时显示/隐藏该列。 ->这是我的 Listview 在 XAML 代码中的定义: 1) 在窗口资源中: 2) 在窗口定义中: -> 加载窗口时: -> 我的 L_class 的定义将获得我的列标题: -> 结果: -> 这是选中/取消选中复选框时调用的 VB 函数:<DataTemplate x:Key="Check_Template">
<CheckBox Name="checkbox" Content="{Binding sL_Name}" Click="CheckBox_Click_1" IsChecked="True"/>
</DataTemplate>
<ListView x:Name="Colum_Select" ItemTemplate="{StaticResource Check_Template}" />
'Creation of a list which will get the headers of the datagrid columns
Dim L_View As New List(Of L_class)
For Each prop In MyDataGrid.Columns
L_View.Add(New L_class(prop.Header.ToString))
Next
'Send them to the Listview in my XAML code
Colum_Select.ItemsSource = L_View
Class L_class
Public L_Name As String
Sub New(One As String)
L_Name = One
End Sub
Public Property sL_Name() As String
Get
Return L_Name
End Get
Set(value As String)
L_Name = value
End Set
End Property
End Class
Private Sub CheckBox_Click_1(sender As Object, e As RoutedEventArgs)
'Get the checkbox which fires the event
Dim senderCB As CheckBox = sender
'Find the column in my datagrid that correspond with the checkbox
Dim item As Object = FindName(senderCB.Content.ToString)
Dim col As DataGridColumn = item
'Hide/Show this column
If (senderCB.IsChecked = True) Then
col.Visibility = Visibility.Visible
Else
col.Visibility = Visibility.Collapsed
End If
End Sub
【问题讨论】: