IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Windows Presentation Foundation Discussion :

[WPF] ListBox & SelectionChanged


Sujet :

Windows Presentation Foundation

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé
    Homme Profil pro
    Étudiant
    Inscrit en
    Novembre 2007
    Messages
    634
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : France, Loire (Rhône Alpes)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Novembre 2007
    Messages : 634
    Par défaut [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 XAML : Sélectionner tout - Visualiser dans une fenêtre à part
    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 XAML : 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
     
    <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

  2. #2
    Invité
    Invité(e)
    Par défaut
    Salut,

    Regardes si t'as bien instancié la commande AccountChangedCommand quelque part ?

  3. #3
    Membre éclairé
    Homme Profil pro
    Étudiant
    Inscrit en
    Novembre 2007
    Messages
    634
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : France, Loire (Rhône Alpes)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Novembre 2007
    Messages : 634
    Par défaut
    Salut,

    j'ai peut-être mal expliqué mon problème.

    En fait, je passe bien dans ma commande (point de debug) lors du clique sur un item de ma liste, mais lors du chargement du contrôle contenant la liste ou lors du databinding des items de ma liste, le premier item est bien sélectionné visuellement, mais ma commande n'est pas appelée.

    Merci

  4. #4
    Invité
    Invité(e)
    Par défaut
    Bizarre !

    Le booléen permettant de savoir si la commande a le droit de s'exécuter ou pas est-il à True ?

  5. #5
    Membre éclairé
    Homme Profil pro
    Étudiant
    Inscrit en
    Novembre 2007
    Messages
    634
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : France, Loire (Rhône Alpes)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Novembre 2007
    Messages : 634
    Par défaut
    Il y a pas de test, la commande est forcément appelée :

    Code c# : 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
     
    #region Commands AccountChanged
            private ICommand _AccountChangedCommand = null;
            public ICommand AccountChangedCommand
            {
                get
                {
                    if (this._AccountChangedCommand == null)
                        this._AccountChangedCommand = new RelayCommand(Param => this.ExecuteAccountChangedCommand((Account)Param));
                    return (this._AccountChangedCommand);
                }
            }
            public void ExecuteAccountChangedCommand(Account Param)
            {
                this.Server.GetTransaction(Param.Id);
            }
     
            #endregion

  6. #6
    Invité
    Invité(e)
    Par défaut
    Tu dis toujours que ta commande est appelée.

    Le plus simple pour savoir si la commande est en cause ou pas est de s'abonner de façon traditionnelle directement sur SelectionChanged et fournir le nom du gestionnaire de l'évènement. Là tu pourras savoir d'où vient le problème de façon précise.

Discussions similaires

  1. wpf, listbox et getchild
    Par pkboo dans le forum Windows Presentation Foundation
    Réponses: 5
    Dernier message: 31/08/2009, 19h40
  2. [WPF][ListBox]Type d'elements d'une ListBox est une form?
    Par bakonu dans le forum Windows Presentation Foundation
    Réponses: 10
    Dernier message: 18/02/2008, 10h00
  3. [WPF] ListBox : evenement SelectionChanged se déclenche lorsque SelectedItemS change
    Par anisb dans le forum Windows Presentation Foundation
    Réponses: 3
    Dernier message: 17/01/2008, 22h29
  4. [WPF] ListBox sélectionner des élément par défaut
    Par Invité dans le forum Framework .NET
    Réponses: 15
    Dernier message: 27/12/2007, 16h25
  5. [WPF] Listbox personnalisée sur 3 colonnes
    Par UNi[FR] dans le forum C#
    Réponses: 1
    Dernier message: 11/09/2007, 17h02

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo