Bonjour,
Dans l'exemple suivant, un ListView, 1 TextBox liés à la valeur 'Name' de l'élément sélectionnée, 1 autre TextBox lié à la valeur 'Picture'...et un bouton.
Le bouton, une fois pressé efface la valeur 'Picture' de l'élément sélectionné.
Je remarque bien que pour le 'Name', une édition dans le champ texte du nom est impactée immédiatement dans le ListView
Pourquoi, svp, quand le bouton d'effacement est pressé, ce n'est pas impacté directement ET dans le ListView ET dans le champ texte correspondant!?
Comment dois-je m'y prendre?
Merci d'avance pour l'aide que vous voudrez bien m'accorder!!
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36 <Window x:Class="MainWindow" xmlns:local="clr-namespace:WpfApplication1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"> <Grid> <Grid.Resources> <local:checkImageURL x:Key="checkImage"/> </Grid.Resources> <ListView Height="230" HorizontalAlignment="Left" Margin="12,12,0,0" Name="PersonListView" VerticalAlignment="Top" Width="445"> <ListView.View> <GridView > <GridViewColumn DisplayMemberBinding="{Binding Id}" Width="80"> <GridViewColumnHeader>Id</GridViewColumnHeader> </GridViewColumn> <GridViewColumn DisplayMemberBinding="{Binding Name}" Width="100"> <GridViewColumnHeader>Name</GridViewColumnHeader> </GridViewColumn> <GridViewColumn Width="100"> <GridViewColumnHeader>Picture</GridViewColumnHeader> <GridViewColumn.CellTemplate> <DataTemplate> <TextBox Text="{Binding Path=Picture, Converter={StaticResource checkImage}}" /> </DataTemplate> </GridViewColumn.CellTemplate> </GridViewColumn> </GridView> </ListView.View> </ListView> <TextBox DataContext="{Binding SelectedItem, ElementName=PersonListView}" Text="{Binding Path=Name, UpdateSourceTrigger =PropertyChanged}" Height="23" HorizontalAlignment="Left" Margin="12,261,0,0" Name="TextBlock1" VerticalAlignment="Top" Width="121" /> <TextBox DataContext="{Binding SelectedItem, ElementName=PersonListView}" Text="{Binding Path=Picture, UpdateSourceTrigger=PropertyChanged}" Height="23" HorizontalAlignment="Left" Margin="218,258,0,0" Name="TextBox1" VerticalAlignment="Top" Width="121" /> <Button Content="Effacer image" Height="23" HorizontalAlignment="Right" Margin="0,258,46,0" Name="Button1" VerticalAlignment="Top" Width="112" /> </Grid> </Window>
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61 Imports System.Collections.ObjectModel Imports System.ComponentModel Class MainWindow Private Sub MainWindow_Loaded(sender As Object, e As System.Windows.RoutedEventArgs) Handles Me.Loaded Dim personList As New List(Of Person)() personList.Add(New Person() With {.Id = 1, .Name = "Alain", .Picture = "Photo d'Alain"}) personList.Add(New Person() With {.Id = 2, .Name = "Pierre", .Picture = "Photo de Pierre"}) personList.Add(New Person() With {.Id = 3, .Name = "Marc", .Picture = "Photo de Marc"}) PersonListView.ItemsSource = personList End Sub Private Sub Button1_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button1.Click Dim p As Person = TryCast(PersonListView.SelectedItem, Person) p.Picture = "" End Sub End Class Public Class checkImageURL Implements IValueConverter Public Function Convert(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.Convert If value = "" Then Return "☺" Else Return "☻" End If Return Nothing End Function Public Function ConvertBack(ByVal value As Object, ByVal targetType As Type, ByVal parameter As Object, ByVal culture As System.Globalization.CultureInfo) As Object Implements IValueConverter.ConvertBack Return Nothing End Function End Class Public Class Person Public Property Id() As Int32 Get Return m_Id End Get Set(value As Int32) m_Id = Value End Set End Property Private m_Id As Int32 Public Property Name() As String Get Return m_Name End Get Set(value As String) m_Name = Value End Set End Property Private m_Name As String Public Property Picture() As String Get Return m_Picture End Get Set(value As String) m_Picture = value End Set End Property Private m_Picture As String End Class
Partager