Bonjour,

Je cherche à ce que la couleur de sélection d'un Item dans une ListBox qui a la focus soit la même que quand elle n'a plus le focus.

Ainsi j'ai ajouté entre <ListBox> et </ListBox> :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
<ListBox.Resources>
                <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Red"/>
                <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Red"/>
            </ListBox.Resources>
Je ne comprends pas pourquoi, les couleurs de sélection d'un Item de la ListBox avec et sans focus sont toujours les mêmes par défaut (à savoir Bleu avec focus et gris sans focus)...

Voyez-vous d'où vient le problème.

Merci.

Voici le code en entier :
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
<Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="50" />
            <RowDefinition Height="*" />
            <RowDefinition Height="50" />
        </Grid.RowDefinitions>
 
        <DatePicker SelectedDate="{Binding FromDate, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Height="25" HorizontalAlignment="Left" Margin="43,12,0,0" Name="datePicker1" VerticalAlignment="Top" Width="115" VerticalContentAlignment="Center" />
        <DatePicker SelectedDate="{Binding ToDate, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Height="25" HorizontalAlignment="Left" Margin="194,12,0,0" Name="datePicker2" VerticalAlignment="Top" Width="115" VerticalContentAlignment="Center" />
        <Label Content="De" Height="25" HorizontalAlignment="Left" Margin="12,12,0,0" Name="label1" VerticalAlignment="Top" VerticalContentAlignment="Center" />
        <Label Content="A" Height="25" HorizontalAlignment="Left" Margin="168,12,0,0" Name="label2" VerticalAlignment="Top" VerticalContentAlignment="Center" />
        <Button Content="Rafraîchir" Command="{Binding RefreshCommand}" Height="23" HorizontalAlignment="Left" Margin="331,13,0,0" Name="button1" VerticalAlignment="Top" Width="75" />
        <ComboBox ItemsSource="{Binding ViewChoices}" SelectedItem="{Binding SelectedViewChoice}" DisplayMemberPath="Name" Height="23" HorizontalAlignment="Right" Margin="0,13,12,0" Name="comboBox1" VerticalAlignment="Top" Width="120"/>
        <Label Content="Affichage" Height="27" HorizontalAlignment="Right" Margin="0,11,138,0" Name="label3" VerticalAlignment="Top" VerticalContentAlignment="Center" Width="64" />
 
        <ListBox Visibility="{Binding IconsViewVisibility, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" Grid.Row="1" ItemsSource="{Binding Images, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" SelectionMode="Multiple" ScrollViewer.HorizontalScrollBarVisibility="Disabled">
            <ListBox.Resources>
                <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Red"/>
                <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Red"/>
            </ListBox.Resources>
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <Image Source="{Binding Data.Location}" Height="{Binding Size, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" Width="{Binding Size, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}">
                        <Image.InputBindings>
                            <MouseBinding MouseAction="LeftDoubleClick" Command="{Binding OpenImageCommand}"/>
                        </Image.InputBindings>
                    </Image>
                </DataTemplate>
            </ListBox.ItemTemplate>
            <ListBox.ItemContainerStyle>
                <Style TargetType="{x:Type ListBoxItem}">
                    <Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
                </Style>
            </ListBox.ItemContainerStyle>
            <ListBox.ItemsPanel>
                <ItemsPanelTemplate>
                    <WrapPanel/>
                </ItemsPanelTemplate>
            </ListBox.ItemsPanel>
        </ListBox>
 
        <ListView Grid.Row="1" Visibility="{Binding DetailsViewVisibility, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" ItemsSource="{Binding Images, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" SelectionMode="Multiple">
            <ListView.View>
                <GridView>
                    <GridViewColumn Header="Nom" Width="200" DisplayMemberBinding="{Binding Data.Name}" />
                    <GridViewColumn Header="Emplacement" Width="200" DisplayMemberBinding="{Binding FolderPath}" />
                    <GridViewColumn Header="Date" Width="160" DisplayMemberBinding="{Binding LastWriteTime}" />
                    <GridViewColumn Header="Taille" Width="80" DisplayMemberBinding="{Binding Length}" />
                </GridView>
            </ListView.View>
            <ListView.ItemContainerStyle>
                <Style TargetType="{x:Type ListViewItem}">
 
                    <Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
                    <Setter Property="local:CommandBehavior.Event" Value="MouseDoubleClick" />
                    <Setter Property="local:CommandBehavior.Command" Value="{Binding DataContext.OpenImageCommand, RelativeSource={RelativeSource Self}}" />
                </Style>
            </ListView.ItemContainerStyle>
        </ListView>
 
        <Grid Grid.Row="2">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="300"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
 
            <Button Content="Exporter" Command="{Binding ExportCommand}" Height="23" HorizontalAlignment="Left" Margin="12,0,0,12" Name="button2" VerticalAlignment="Bottom" Width="75" IsDefault="True" Grid.Column="0"/>
            <Button Content="Quitter" Command="{Binding CloseCommand}" Height="23" HorizontalAlignment="Right" Margin="0,0,12,12" Name="button3" VerticalAlignment="Bottom" Width="75" IsCancel="True" Grid.Column="2" />
            <Button Command="{Binding SelectAllCommand}" Content="Tout sélectionner" Height="23" Margin="19,0,153,12" Name="button4" VerticalAlignment="Bottom" Grid.Column="1" />
            <Button Command="{Binding UnselectAllCommand}" Content="Tout désélectionner" Height="23" Margin="153,0,19,12" Name="button5" VerticalAlignment="Bottom" Grid.Column="1" />
        </Grid>
    </Grid>