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 :

Binding ItemSeleted ComboBox


Sujet :

Windows Presentation Foundation

  1. #1
    Membre habitué
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2013
    Messages
    93
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Novembre 2013
    Messages : 93
    Points : 127
    Points
    127
    Par défaut Binding ItemSeleted ComboBox
    Bonjour/Bonsoir

    Je viens de regarder pas mal de tutoriel sur internet mais rien à faire (plein = env 10) je bloque sur le binding de sélection.

    Voici le code actuel que j'ai.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <ComboBox Height="30" HorizontalAlignment="Left" Margin="534,39,0,0" Name="comboBox1" VerticalAlignment="Top" Width="170" SelectionChanged="comboBox1_SelectionChanged" SelectedItem="{Binding SelectedPath, Mode=OneWay}"/>
    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
    public partial class Form : UserControl, INotifyPropertyChanged
        {
     
            public Form(Main main)
            {
                InitializeComponent();
                this.comboBox1.ItemsSource = Data.DataBot.ListTypeAction(); //Item source équivaut à une List<String> Aucun soucis ils s'affichent tous dans la comboBox
            }
     
            private void comboBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
            {
                MessageBox.Show(this.SelectedPath);
            }
     
            private string selectedPath;
            public string SelectedPath
            {
                get
                {
                    return selectedPath;
                }
                set
                {
                    if(value != null)
                        selectedPath = value;
                    OnPropertyChanged("SelectedPath");
                }
            }
     
            public void OnPropertyChanged(string propertyName)
            {
                if (PropertyChanged != null)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
                }
            }
     
            public event PropertyChangedEventHandler PropertyChanged;
     
        }
     
    }
    J'ai inséré un événement pour voir si la propriété change bien ou non. Et le truc c'est que c'est complétement vide.
    Donc si vous avez une astuce ou si vous pouvez me corriger mon code. (je suis preneur de tous conseils et critique faut pas hésiter à en balancer)

    Merci.

  2. #2
    Nouveau membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2011
    Messages
    62
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Transports

    Informations forums :
    Inscription : Mai 2011
    Messages : 62
    Points : 35
    Points
    35
    Par défaut
    Hello,

    Je pense que c'est normal , parce que tu as bindé ta propriété en mode oneway soit en lecture seul .

    Mets plutôt ça et essaye :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <ComboBox Height="30" HorizontalAlignment="Left" Margin="534,39,0,0" Name="comboBox1" VerticalAlignment="Top" Width="170" SelectionChanged="comboBox1_SelectionChanged" SelectedItem="{Binding SelectedPath, Mode=TwoWay}"/>

  3. #3
    Membre expert
    Avatar de GuruuMeditation
    Homme Profil pro
    .Net Architect
    Inscrit en
    Octobre 2010
    Messages
    1 705
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 49
    Localisation : Belgique

    Informations professionnelles :
    Activité : .Net Architect
    Secteur : Conseil

    Informations forums :
    Inscription : Octobre 2010
    Messages : 1 705
    Points : 3 568
    Points
    3 568
    Par défaut
    Tu n'as pas mis ton DataContext non plus. Dans le constructeur mets :
    Code C# : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    DataContext = this;
    Microsoft MVP : Windows Platform

    MCPD - Windows Phone Developer
    MCPD - Windows Developer 4

    http://www.guruumeditation.net

    “If debugging is the process of removing bugs, then programming must be the process of putting them in.”
    (Edsger W. Dijkstra)

  4. #4
    Membre habitué
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2013
    Messages
    93
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Novembre 2013
    Messages : 93
    Points : 127
    Points
    127
    Par défaut
    Exact sans le datacontext ça ne fonctionnait pas. Merci à vous 2.

    @GuruuMeditation : pourrais-tu m'en dire plus sur le rôle exact de ce datacontext car sur la msdn je comprends pas de trop. Et j'utilisais quelque binding sans forcément le déclarer.

Discussions similaires

  1. double binding sur combobox >>> possible?
    Par waspy59 dans le forum Windows Presentation Foundation
    Réponses: 16
    Dernier message: 03/11/2009, 23h47
  2. Binding ListBox - ComboBox
    Par sodaw dans le forum Windows Presentation Foundation
    Réponses: 10
    Dernier message: 26/10/2009, 09h52
  3. [Spring MVC] <spring:bind sur combobox
    Par coyote999 dans le forum Spring Web
    Réponses: 2
    Dernier message: 28/02/2008, 14h32
  4. binding entre combobox et datagridview
    Par Mathieu.Nanoux dans le forum Windows Forms
    Réponses: 8
    Dernier message: 08/03/2007, 00h31

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