Как получить текст элемента ListView по нажатию?
У меня есть listview, который заполняется через БД при помощи ItemSource. Я хочу при нажатии мышкой на элемент получить то, что там написано. Сразу говорю, пробовал string s = ListView.SelectedItem.text; выдаёт ошибку.
UPD: Прикладываю код
CS:
public List<Specialty> specs { get; set; }
public List<Groups> groups { get; set; }
public List<Subjects> subj { get; set; }
public Specialty specialtyShow { get; set; }
public Groups groupsShow { get; set; }
public Subjects subjectsShow { get; set; }
public MainWindow()
{
InitializeComponent();
this.DataContext = this;
specialtyShow = new Specialty();
groupsShow = new Groups();
subjectsShow = new Subjects();
specs = DB.Connection.Specialty.ToList();
groups = DB.Connection.Groups.ToList();
subj = DB.Connection.Subjects.ToList();
ListViewSpecialty.ItemsSource = specs;
ListViewGroups.ItemsSource = groups;
ListViewSubjects.ItemsSource = subj;
}
Xaml:
<ListView Name="ListViewSpecialty" Background="Transparent" Grid.Row="0" ItemsSource="{Binding Specialty}" SelectionMode="Single">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Label Foreground="#FF8686" Content="{Binding Name}"></Label>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<ListView Name="ListViewGroups" Background="Transparent" Grid.Row="1" ItemsSource="{Binding Groups}" SelectionMode="Single">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Label Foreground="#FF8686" Content="{Binding Name}"></Label>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<ListView Name="ListViewSubjects" Background="Transparent" Grid.Row="2" ItemsSource="{Binding Subjects}" SelectionMode="Single">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Label Foreground="#FF8686" Content="{Binding Name}"></Label>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>