Listview项未更新wpf vb.net

Listview项未更新wpf vb.net,wpf,vb.net,listview,Wpf,Vb.net,Listview,我正在创建一个应用程序,在其中打开一个新窗口,该窗口在listview中有选项可供选择,我们提取listview中的一个项目,并将其传递到另一个窗口上的另一个listview。我可以在主窗口上填充listview,并可以验证是否在调试期间使用.items.count添加了项,但它们不是实时添加的。如果我使用.show打开窗口的另一个实例,我会看到其中的项目,但由于我不打算关闭主窗口,如何“刷新”列表视图以清楚地显示其中的选项 我已经读到,如果listview绑定到一个表,您可以重新绑定数据来刷新

我正在创建一个应用程序,在其中打开一个新窗口,该窗口在listview中有选项可供选择,我们提取listview中的一个项目,并将其传递到另一个窗口上的另一个listview。我可以在主窗口上填充listview,并可以验证是否在调试期间使用.items.count添加了项,但它们不是实时添加的。如果我使用.show打开窗口的另一个实例,我会看到其中的项目,但由于我不打算关闭主窗口,如何“刷新”列表视图以清楚地显示其中的选项

我已经读到,如果listview绑定到一个表,您可以重新绑定数据来刷新它,但是由于这个listview没有绑定到任何东西,只是使用.add函数向它添加项目,我不确定如何“刷新”它来显示值

编辑: 这是我目前的代码

Public Class ObservableColl

    Public Structure Steps
        Private _Steps As List(Of String)
        Property Steps() As List(Of String)
            Get
                Return _Steps
            End Get
            Set(ByVal value As List(Of String))
                _Steps = value
            End Set
        End Property
    End Structure

    Dim songs As New ObservableCollection(Of Steps)

End Class


 Private Sub CloseForm()
        Dim stepArr As String() = Split(sCommon.presetSteps, ",")
        Dim entries As New List(Of String)

        For i = 0 To stepArr.Count - 1
            entries.Add(stepArr(i))
        Next

        sCommon.form1.entries.Add(New Steps With {.Steps = entries}) 'Add list entries to the observableCollection
        sCommon.form1.lvwCurrentSteps.DataContext = entries 'Assign the DataContext property to the observableCollection

        If Not PresetList Is Nothing Then 
            Me.Close() 'Close this form and focus returns to the main window
        End If

    End Sub

<ListView Margin="49,23,0,33" HorizontalAlignment="Left" Width="230" Name="lvwCurrentSteps" SelectionMode="Multiple" ItemsSource="{Binding}" >
            <ListView.ItemContainerStyle>
                <Style TargetType="{x:Type ListViewItem}">
                    <Setter Property="BorderBrush" Value="LightGray" />
                    <Setter Property="BorderThickness" Value="0,0,0,1" />
                </Style>
            </ListView.ItemContainerStyle>
            <ListView.View>
                <GridView x:Name="myGridView">
                    <GridViewColumn Width="220" Header="Steps to run"  DisplayMemberBinding="{Binding Path=Steps}">
                    </GridViewColumn>                                    
                </GridView>
            </ListView.View>
        </ListView>

仅从这段代码很难区分,但看起来您的逻辑在这两行中是反向的:

sCommon.form1.entries.Add(New Steps With {.Steps = entries}) 'Add list entries to the observableCollection
sCommon.form1.lvwCurrentSteps.DataContext = entries 'Assign the DataContext property to the observableCollection
我希望您想要使用的DataContext是您刚刚添加到的集合,而不是您添加的局部变量,它是一个字符串列表,因此没有支持DisplayMemberBinding的Steps属性。ObservaleColl类的设置方式似乎也有点奇怪,ObservaleCollection对象包含一个列表


我不确定计数发生了什么,但您应该验证您的基本逻辑是否真正符合您的要求。

很抱歉,我无法说明问题的原因,但为什么不将Listview绑定到集合,而将项目添加到该集合中呢?如果可能的话,我尽量避免在代码隐藏中直接操作WPF控件。
sCommon.form1.entries.Add(New Steps With {.Steps = entries}) 'Add list entries to the observableCollection
sCommon.form1.lvwCurrentSteps.DataContext = entries 'Assign the DataContext property to the observableCollection