[WPF] ListBox & SelectionChanged
Bonjour à tous,
j'ai un bug dans ma tête... J'ai une ListBox, une liste d'items est bindé sur la propriété ItemsSource... Jusque là aucun, soucis...
En fait, j'ai du modifier quelque chose sans m'en rendre compte. Mais l'event SelectionChanged n'est pas émis lors du chargement du contrôle / lors du binding alors qu'il me semblait pourtant qu'il l'était auparavant...
Code:
1 2 3 4 5 6 7 8 9 10
|
<UserControl.Resources>
<Converters:BinariesToImageSourceConverter x:Key="BinariesToImageSourceConverter" />
<Converters:AmmountToTextConverter x:Key="AmmountToTextConverter" />
<CollectionViewSource Source="{Binding Data.Accounts}" x:Key="Data">
<CollectionViewSource.GroupDescriptions>
<PropertyGroupDescription PropertyName="Type" />
</CollectionViewSource.GroupDescriptions>
</CollectionViewSource>
</UserControl.Resources> |
Code:
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
|
<ListBox Name="List" Grid.Row="0" Grid.Column="0" ItemsSource="{Binding Source={StaticResource Data}}" Background="{x:Null}" BorderBrush="{x:Null}" Utils:CommandBehavior.Event="SelectionChanged" Utils:CommandBehavior.Command="{Binding AccountChangedCommand}" Utils:CommandBehavior.CommandParameter="{Binding RelativeSource={RelativeSource Self}, Path=SelectedItem}">
<ListBox.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Orange" />
<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Orange" />
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
</Style>
</ListBox.Resources>
<ListBox.GroupStyle>
<GroupStyle HidesIfEmpty="True">
<GroupStyle.ContainerStyle>
<Style TargetType="GroupItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="GroupItem">
<Expander IsExpanded="True" >
<Expander.Header>
<TextBlock Grid.Column="0" Text="{Binding Name}" Foreground="White" FontWeight="Bold" />
</Expander.Header>
<ItemsPresenter/>
</Expander>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</GroupStyle.ContainerStyle>
</GroupStyle>
</ListBox.GroupStyle>
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="70" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="20" />
<RowDefinition Height="20" />
<RowDefinition Height="30" />
</Grid.RowDefinitions>
<Image Source="{Binding Logo, Converter={StaticResource BinariesToImageSourceConverter}}" Grid.Column="0" Grid.Row="0" Grid.RowSpan="3" Margin="5" />
<TextBlock Text="{Binding Name}" Grid.Row="0" Grid.Column="1" VerticalAlignment="Center" FontWeight="Bold" FontSize="14" Foreground="White" />
<TextBlock Text="{Binding Number}" Grid.Row="1" Grid.Column="1" VerticalAlignment="Center" Foreground="White" />
<TextBlock Text="{Binding Ammount, Converter={StaticResource AmmountToTextConverter}}" Grid.Row="2" Grid.Column="1" VerticalAlignment="Center" Foreground="White" FontWeight="Bold" HorizontalAlignment="Right" Margin="0,0,10,0" />
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox> |
Quelqu'un a une idée ?
Merci d'avance.
NeoKript