I'm trying to do something pretty simple, but I'm not super experienced on WPF: I want to click on an item in a list view, popup a dialog that will delete or update that item, then refresh the list, without calling up the delete/edit dialog again.
Here's the code I'm working with: XAML:
<ListView x:Name="peopleListView"
Height="280"
Margin="0,5,0,0"
SelectionChanged="peopleListView_SelectionChanged">
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
</Style>
</ListView.ItemContainerStyle>
<ListView.ItemTemplate>
<DataTemplate>
<uc:PersonControl PersonDetails="{Binding}"/>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
The codebehind is this:
private void peopleListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
PersonDetails selectedPersonDetails = (PersonDetails) peopleListView.SelectedItem;
EditAndDeletePeopleWindow editAndDelPeople = new EditAndDeletePeopleWindow(selectedPersonDetails);
editAndDelPeople.ShowDialog();
DisplayPeopleFromDatabase();
}
The elements of the list are a control. Every time the DisplayPeopleFromDatabase runs, the SelectionChanged even fires, which calls up the edit dialog.
Here's the DisplayPeopleFromDatabase code:
private void DisplayPeopleFromDatabase()
{
List<PersonDetails> personDetailList = new List<PersonDetails>(dbPlanningService.GetAllPeopleList());
if (personDetailList != null)
{
peopleListView.ItemsSource = personDetailList;
}
}