Answer the question
In order to leave comments, you need to log in
How to edit a list item in WPF?
Greetings.
There is a WPF form with a list on it
<ListView x:Name="FilmListView"
ItemsSource="{Binding Path=FilmList}"
ItemTemplate="{StaticResource FilmView}"
SelectedItem="{Binding Path=SelectedFilm, Mode=OneWayToSource, UpdateSourceTrigger=PropertyChanged}"
IsSynchronizedWithCurrentItem="True"/>
<WrapPanel>
<TextBlock Text="Name: " />
<TextBlock Text="{Binding Path=SelectedFilm.Name, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" />
</WrapPanel>
<WrapPanel>
<TextBlock Text="Name: " />
<TextBox Text="{Binding Path=EditFilm.Name, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
</WrapPanel>
Answer the question
In order to leave comments, you need to log in
There are two options, the first one is editing SelectedFilm directly (I think it's the best option - you change it, press the Save button to apply the changes),
and the second is to link SelectedFilm and EditFilm.
If you have SelectedFilm and EditFilm defined in the view model, then you need to add the transfer of the SelectedFilm link to EditFilm and back after the change. For example, the selected element has changed, the view model copies a link to it in EditFilm. Click the save button, the data from the EditFilm is copied to the selected element, and the EditFilm is set to zero.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question