Hi!
I want to run SelectionChanged Event in listView which is located inside another list view. The code look like this:
<Window x:Class="Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300"
Name="Window1">
<Grid>
<ListView DataContext="{Binding ElementName=Window1}"
ItemsSource="{Binding ItemList}"
BorderThickness="0"
x:Name="itemListView"
SelectionChanged="itemListView_SelectionChanged">
<ListView.ItemTemplate>
<DataTemplate>
<ListView DataContext="{Binding ElementName=Window1}"
ItemsSource="{Binding SubList}"
BorderThickness="0"
x:Name="subListView"
SelectionChanged="subListView_SelectionChanged">
<ListView.ItemTemplate>
<DataTemplate>
<Label Content="{Binding}"/>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
</Window>
Class Window1
Private _itemList As List(Of String)
Public Property ItemList() As List(Of String)
Get
Return _itemList
End Get
Set(ByVal value As List(Of String))
_itemList = value
End Set
End Property
Private _subList As List(Of String)
Public Property SubList() As List(Of String)
Get
Return _subList
End Get
Set(ByVal value As List(Of String))
_subList = value
End Set
End Property
Public Sub New()
_itemList = New List(Of String)
_subList = New List(Of String)
_itemList.Add("item1")
_itemList.Add("item2")
_itemList.Add("item3")
_subList.Add("sub1")
_subList.Add("sub2")
' This call is required by the Windows Form Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
End Sub
Private Sub subListView_SelectionChanged(ByVal sender As System.Object, ByVal e As System.Windows.Controls.SelectionChangedEventArgs)
MsgBox("Selection Changed")
End Sub
End Class
If user change selection in subListView the SelectionChanged event should be run.
So if user select sub1 from item1 message box should apper. The same, if he choose sub1 from item2. And it works but only on the first time when user change selection.
If I try to repeat the action - select sub from item1 nothing happen, because sub1 is still selected in item1 and item2.
How can I resolve this problem? I need to run selectionChanged event whenever user change his selection.
Thanks in advance for your help.!