Bonjour,
aujourd'hui je fais face à un problème curieux.
j'ai une listview
ListViewItemStyleSelector n'applique pour le moment que un seul style, celui qui suit (voir en gras l'event KeyDown) :
Code : Sélectionner tout - Visualiser dans une fenêtre à part <ListView DockPanel.Dock="Left" x:Name="t_concepteur" ItemContainerStyleSelector="{StaticResource ListViewItemStyleSelector}"/>
le gestionnaire d'évènement est le suivant :
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109 <Style x:Key="ListviewItemStyle_1" TargetType="ListViewItem"> <Setter Property="SnapsToDevicePixels" Value="True"/> <Setter Property="Padding" Value="4,1"/> <Setter Property="HorizontalContentAlignment" Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/> <Setter Property="VerticalContentAlignment" Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/> <Setter Property="Background" Value="Transparent"/> <Setter Property="BorderBrush" Value="Transparent"/> <Setter Property="BorderThickness" Value="1"/> <Setter Property="FocusVisualStyle" Value="{StaticResource FocusVisualStyle_1}"/> <Setter Property="Visibility" Value="{Binding Path=visibilite}"/> <Setter Property="AllowDrop" Value="True"/> <EventSetter Event="Mouse.PreviewMouseDown" Handler="listviewitem_mousedown"/> <EventSetter Event="Mouse.PreviewMouseUp" Handler="listviewitem_mouseup"/> <EventSetter Event="DragOver" Handler="listviewitem_DragOver"/> <EventSetter Event="Drop" Handler="listviewitem_Drop"/> <EventSetter Event="KeyDown" Handler="listviewitem_KeyDown" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type ListViewItem}"> <Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="true"> <Grid > <Grid.RowDefinitions> <RowDefinition Height="18" /> <RowDefinition Height="Auto"/> </Grid.RowDefinitions> <Border Grid.Row="0" x:Name="row0" BorderBrush="Red" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" CornerRadius="5"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto" MaxWidth="20"/> <ColumnDefinition Width="20" MaxWidth="20"/> <ColumnDefinition Width="{Binding Path=profondeur, Converter={StaticResource profondeurmargetreeviewitem}}" MaxWidth="{Binding Path=profondeur, Converter={StaticResource profondeurmargetreeviewitem}}"/> <ColumnDefinition Width="20" MaxWidth="20"/> <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="*" /> </Grid.ColumnDefinitions> <TextBlock x:Name="rang" HorizontalAlignment="Left" Grid.Column="0" Grid.Row="0" Text="{Binding Path=rang}" Style="{StaticResource labelstyle2}"/> <ToggleButton x:Name="HeadExpander" Content="{Binding Path=type, Converter={StaticResource EnteteHierarchique}}" Style="{StaticResource AnimatedExpanderButtonTemp}" Grid.Column="4" Grid.Row="0" HorizontalAlignment="Left"/> <ToggleButton Grid.Column="3" Grid.Row="0" HorizontalAlignment="Center" VerticalAlignment="Center" SnapsToDevicePixels="True" x:Name="Expander" Style="{StaticResource TreeviewTogglePlusMoins}" IsChecked="{Binding Path=IsExpand}" ClickMode="Press" /> <TextBox x:Name="textboxref" Text="{Binding Path=lib_court}" Style="{StaticResource TextBoxStyle2}" Grid.Column="5" Grid.Row="0" HorizontalAlignment="Stretch"/> </Grid> </Border> <ControlTemplate.Triggers> <MultiTrigger> <MultiTrigger.Conditions> <Condition Property="IsMouseOver" Value="True"/> </MultiTrigger.Conditions> <Setter Property="Background" TargetName="row0" Value="{StaticResource Item.MouseOver.Background}"/> <Setter Property="BorderBrush" TargetName="row0" Value="{StaticResource Item.MouseOver.Border}"/> <Setter Property="Background" TargetName="textboxref" Value="{StaticResource Item.MouseOver.Background}"/> </MultiTrigger> <MultiTrigger> <MultiTrigger.Conditions> <Condition Property="Selector.IsSelectionActive" Value="False"/> <Condition Property="IsSelected" Value="True"/> </MultiTrigger.Conditions> <Setter Property="Background" TargetName="row0" Value="{StaticResource Item.SelectedInactive.Background}"/> <Setter Property="BorderBrush" TargetName="row0" Value="{StaticResource Item.SelectedInactive.Border}"/> <Setter Property="Background" TargetName="textboxref" Value="{StaticResource Item.SelectedInactive.Background}"/> </MultiTrigger> <MultiTrigger> <MultiTrigger.Conditions> <Condition Property="Selector.IsSelectionActive" Value="True"/> <Condition Property="IsSelected" Value="True"/> </MultiTrigger.Conditions> <Setter Property="Background" TargetName="row0" Value="{StaticResource Item.SelectedActive.Background}"/> <Setter Property="BorderBrush" TargetName="row0" Value="{StaticResource Item.SelectedActive.Border}"/> <Setter Property="Background" TargetName="textboxref" Value="{StaticResource Item.SelectedActive.Background}"/> </MultiTrigger> <Trigger Property="IsEnabled" Value="False"> <Setter Property="TextElement.Foreground" TargetName="row0" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/> </Trigger> <Trigger SourceName="HeadExpander" Property="IsChecked" Value="True"> <Trigger.EnterActions> <BeginStoryboard> <Storyboard> <DoubleAnimation Storyboard.TargetName="ExpanderContent" Storyboard.TargetProperty="(ContentPresenter.LayoutTransform).(ScaleTransform.ScaleY)" To="1" Duration="0:0:0.4"/> </Storyboard> </BeginStoryboard> </Trigger.EnterActions> <Trigger.ExitActions> <BeginStoryboard> <Storyboard> <DoubleAnimation Storyboard.TargetName="ExpanderContent" Storyboard.TargetProperty="(ContentPresenter.LayoutTransform).(ScaleTransform.ScaleY)" To="0" Duration="0:0:0.4"/> </Storyboard> </BeginStoryboard> </Trigger.ExitActions> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style>
Al'exécution lorsque j'appui sur une touche j'obtiens bien le "hello", mais juste après avoir fermé la boite de dialogue l'exception suivante se produit :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4 Private Sub listviewitem_KeyDown(sender As Object, e As KeyEventArgs) MsgBox("hello") End Sub
Code : Sélectionner tout - Visualiser dans une fenêtre à part TargetType 'ListViewItem' ne correspond pas au type de l'élément 'Control'
Lorsque je désactive le style ça marche sans problème. J'imagine qu'il y'a quelque chose qui cloche dans la définition du style ListviewItemStyle_1
Toute aide est la bienvenue, merci d'avance.
Partager