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

Silverlight Discussion :

[C#][VS 2010][Silverlight]Problème affichage d'une listbox [Débutant(e)]


Sujet :

Silverlight

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Inscrit en
    Février 2004
    Messages
    206
    Détails du profil
    Informations forums :
    Inscription : Février 2004
    Messages : 206
    Par défaut [C#][VS 2010][Silverlight]Problème affichage d'une listbox
    Bonjour,

    j'essaye depuis ce matin d'utiliser un exemple obtenu sur le net. Il s'agit d'un drag and drop d'une ListBox à une autre. Je veux afficher le résultat de la fenêtre 2 lorsque je sélectionne un nom. Le problème c'est que je n'arrive pas ca plante. Merci de m'aider ou de me donne une direction.

    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
    <UserControl x:Class="Silverlight4.DragDropListBox.MainPage"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:toolKit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit">
        <Grid x:Name="LayoutRoot" Background="White" HorizontalAlignment="Center" VerticalAlignment="Center">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <TextBlock Text="Drag &amp; Drop ListBox Demo" FontSize="20" FontWeight="Bold" Foreground="Red" Margin="10"  Grid.Row="0"/>
            <StackPanel Orientation="Horizontal" Margin="10" Grid.Row="1">
     
                <toolKit:ListBoxDragDropTarget AllowDrop="True">
                    <ListBox x:Name="customerListBoxMain" Height="200" Width="200" DisplayMemberPath="Name">
                        <ListBox.ItemsPanel>
                            <ItemsPanelTemplate>
                                <StackPanel Orientation="Vertical"/>
                            </ItemsPanelTemplate>
                        </ListBox.ItemsPanel>
                    </ListBox>
                </toolKit:ListBoxDragDropTarget>
     
                <TextBlock Width="20" />
     
                <toolKit:ListBoxDragDropTarget AllowDrop="True">
                    <ListBox Height="200" Width="200" DisplayMemberPath="Name" SelectionChanged="ListBox_SelectionChanged">
                        <ListBox.ItemsPanel>
                            <ItemsPanelTemplate>
                                <StackPanel Orientation="Vertical"/>
                            </ItemsPanelTemplate>
                        </ListBox.ItemsPanel>
                    </ListBox>
                </toolKit:ListBoxDragDropTarget>
     
            </StackPanel>
        </Grid>
    </UserControl>

    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
    19
    20
    21
    22
    23
     
    using System.Collections.ObjectModel;
     
    namespace Silverlight4.DragDropListBox
    {
        public class PersonDataProvider
        {
            public static ObservableCollection<Person> GetData()
            {
                return new ObservableCollection<Person>
                            {
                                new Person { Name = "Akash Sharma" },
                                new Person { Name = "Vinay Sen" },
                                new Person { Name = "Lalit Narayan" },
                                new Person { Name = "Madhumita Chatterjee" },
                                new Person { Name = "Priyanka Patil" },
                                new Person { Name = "Kumar Sanu" },
                                new Person { Name = "Victor Kapoor" }
     
                            };
            }
        }
    }

    Code C# : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
    namespace Silverlight4.DragDropListBox
    {
        public class Person
        {
            public string Name { get; set; }
        }
    }

    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
    19
    20
    21
    22
    23
     
    using System.Windows.Controls;
    using System.Windows;
     
    namespace Silverlight4.DragDropListBox
    {
        public partial class MainPage : UserControl
        {
            public MainPage()
            {
                InitializeComponent();
     
                customerListBoxMain.ItemsSource = PersonDataProvider.GetData();
            }
     
            private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
            {
                ListBoxItem lib = ((sender as ListBox).SelectedItem as ListBoxItem);
                string libelle = lib.ToString();
                //MessageBox.Show("Personne : " + libelle);
            }
        }
    }

  2. #2
    Membre éprouvé
    Profil pro
    Inscrit en
    Novembre 2005
    Messages
    876
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Novembre 2005
    Messages : 876
    Par défaut
    Pourrais-tu être plus précis sur la nature de ton problème ...

    Qu'est-ce qui fonctionne et qu'est-ce qui ne fonctionne pas ?

    Quand tu "drag" sur un élément de ton listbox, le vois-tu se déplacer ?

  3. #3
    Membre confirmé
    Inscrit en
    Février 2004
    Messages
    206
    Détails du profil
    Informations forums :
    Inscription : Février 2004
    Messages : 206
    Par défaut
    merci Golzinne d'essayer de m'aider. Je vais essayer d'expliquer ce que je veux faire. L'exemple que j'ai trouvé fonctionne très bien puisque j'arrive à faire des drag and drop d'une ListBox à l'autre sans problème. Ce que j'ai voulu faire c'est d'ajouter la ListBox_SelectionChanged mais je ne sais pas comment faire pour afficher les éléments sur lesquels je clique.

  4. #4
    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 : 50
    Localisation : Belgique

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

    Informations forums :
    Inscription : Octobre 2010
    Messages : 1 705
    Par défaut
    SelectedItem retourne une Person, pas un ListBoxItem.
    Dans ta fonction doit être plutôt :
    Code c# : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
            private void ListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
            {
                var lib = ((sender as ListBox).SelectedItem as Person);
                string libelle = lib.Name;
                MessageBox.Show("Personne : " + libelle);
            }

  5. #5
    Membre confirmé
    Inscrit en
    Février 2004
    Messages
    206
    Détails du profil
    Informations forums :
    Inscription : Février 2004
    Messages : 206
    Par défaut
    Merci beaucoup pour ton aide !

  6. #6
    Membre confirmé
    Inscrit en
    Février 2004
    Messages
    206
    Détails du profil
    Informations forums :
    Inscription : Février 2004
    Messages : 206
    Par défaut
    maintenant j'ai fait évoluer ma recherche sur les draganddropListbox et j'aimerais votre avis. Avec :
    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
     
    <UserControl x:Class="Silverlight4.DragDropListBox.MainPage"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:toolKit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit">
        <Grid x:Name="LayoutRoot" Background="White" HorizontalAlignment="Center" VerticalAlignment="Center">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <TextBlock Text="Drag &amp; Drop ListBox Demo" FontSize="20" FontWeight="Bold" Foreground="Red" Margin="10"  Grid.Row="0"/>
            <StackPanel Orientation="Horizontal" Margin="10" Grid.Row="1">
                <toolKit:ListBoxDragDropTarget AllowDrop="True">
                    <ListBox x:Name="customerListBoxMain" Height="200" Width="200" 
                                DisplayMemberPath="diplome">
                        <ListBox.ItemsPanel>
                            <ItemsPanelTemplate>
                                <StackPanel Orientation="Vertical"/>
                            </ItemsPanelTemplate>
                        </ListBox.ItemsPanel>
                    </ListBox>
                </toolKit:ListBoxDragDropTarget>
                <TextBlock Width="20" />
                <toolKit:ListBoxDragDropTarget AllowDrop="True">
                    <ListBox Height="200" Width="200" DisplayMemberPath="diplome">
                        <ListBox.ItemsPanel>
                            <ItemsPanelTemplate>
                                <StackPanel Orientation="Vertical"/>
                            </ItemsPanelTemplate>
                        </ListBox.ItemsPanel>
                    </ListBox>
                </toolKit:ListBoxDragDropTarget>
            </StackPanel>
        </Grid>
    </UserControl>


    et
    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
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
     
    using System.Windows.Controls;
    using System.Windows;
    using System.Net;
    using System.Runtime.Serialization.Json;
    using System;
     
     
    namespace Silverlight4.DragDropListBox
    {
        public partial class MainPage : UserControl
        {
     
            public Diplome[] dlp = {new Diplome { diplome = "Essai 1" }, new Diplome { diplome = "Essai 2" },
                                    new Diplome { diplome = "Essai 3" }, new Diplome { diplome = "Essai 4" }};
     
            public MainPage()
            {
                InitializeComponent();
                customerListBoxMain.ItemsSource = dlp;
            }
        }
     
        public class Diplome
        {
            public string num_diplome { get; set; }
            public string diplome { get; set; }
            public string date_arrete { get; set; }
            public string type_diplome { get; set; }
            public string libelle_diplome { get; set; }
            public int debut { get; set; }
            public int fin { get; set; }
        }
    }

    je n'arrive pas à comprendre pourquoi dans ce cas, lorsque je déplace d'une fenetre à l'autre un libéllé Essai1 oi autre il ne disparait pas de l'endroit où je l'ai pris mais il apparait là où je l'ai laché. Une fois laché si je le prends pour le remettre dans sa listbox de départ il ne disparait pas de là où je l'ai pris

    Merci beaucoup

    P.S. ne faites pas attention aux closes using superflues

  7. #7
    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 : 50
    Localisation : Belgique

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

    Informations forums :
    Inscription : Octobre 2010
    Messages : 1 705
    Par défaut
    C'est parce que tu utilises un array[]. Si tu utilises ObservableCollection (ou toute collection qui implémente INotifyCollectionChanged ), ça va aller.
    C'est la façon dont le contrôle fonctionne, si ce n'est pas une collection qui implémente INotifyCollectionChanged, il n'y a pas toutes les possibilités de drag and drop.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 5
    Dernier message: 18/02/2008, 13h48
  2. Problème d'affichage dans une listbox
    Par swap_nibble dans le forum Interfaces Graphiques
    Réponses: 3
    Dernier message: 25/01/2008, 17h29
  3. Problème affichage d'une fenetre dans une fenetre
    Par zuzuu dans le forum Windows
    Réponses: 10
    Dernier message: 03/10/2007, 15h26
  4. problème affichage dans une page html
    Par ljoly dans le forum Flash
    Réponses: 6
    Dernier message: 22/09/2006, 16h57
  5. Problème affichage d'une image
    Par om.rava dans le forum Langage
    Réponses: 3
    Dernier message: 04/12/2005, 09h56

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